import 'dotenv/config'; import express, { Application, Request, Response, NextFunction } from 'express'; import cors from 'cors'; import helmet from 'helmet'; import rateLimit from 'express-rate-limit'; // Import routes import authRoutes from './routes/auth'; import eventRoutes from './routes/events'; import noteRoutes from './routes/notes'; import aiRoutes from './routes/ai'; // Import error handler import { errorHandler } from './middleware/errorHandler'; const app: Application = express(); const PORT = process.env.PORT || 3000; // Security middleware app.use(helmet()); // Rate limiting - increased for testing // TEMPORARILY DISABLED FOR TESTING // const limiter = rateLimit({ // windowMs: 15 * 60 * 1000, // 15 minutes // max: 500, // limit each IP to 500 requests per windowMs // message: { error: 'Too many requests, please try again later' }, // standardHeaders: true, // legacyHeaders: false, // }); // app.use('/api', limiter); // CORS configuration - support multiple origins (comma-separated) const corsOrigins = process.env.CORS_ORIGIN?.split(',').map(o => o.trim()) || ['http://localhost:5173']; app.use(cors({ origin: corsOrigins.length > 1 ? corsOrigins : corsOrigins[0], credentials: true, })); // Body parser with size limit (prevent DoS attacks) app.use(express.json({ limit: '10kb' })); // Health check app.get('/health', (_req: Request, res: Response) => { res.json({ status: 'ok', timestamp: new Date().toISOString() }); }); // API Routes app.use('/api/auth', authRoutes); app.use('/api/events', eventRoutes); app.use('/api/notes', noteRoutes); app.use('/api/ai', aiRoutes); // 404 handler app.use((_req: Request, res: Response) => { res.status(404).json({ error: 'Not found' }); }); // Error handler app.use(errorHandler); // Start server app.listen(PORT, () => { console.log(`🚀 Server running on http://localhost:${PORT}`); console.log(`📝 Environment: ${process.env.NODE_ENV || 'development'}`); }); export default app;