This commit is contained in:
Matthias Hochmeister
2026-02-23 17:08:58 +01:00
commit f09748f4a1
97 changed files with 17729 additions and 0 deletions

68
backend/src/app.ts Normal file
View File

@@ -0,0 +1,68 @@
import express, { Application, Request, Response } from 'express';
import cors from 'cors';
import helmet from 'helmet';
import rateLimit from 'express-rate-limit';
import environment from './config/environment';
import logger from './utils/logger';
import { errorHandler, notFoundHandler } from './middleware/error.middleware';
const app: Application = express();
// Security middleware
app.use(helmet());
// CORS configuration
app.use(cors({
origin: environment.cors.origin,
credentials: true,
}));
// Rate limiting
const limiter = rateLimit({
windowMs: environment.rateLimit.windowMs,
max: environment.rateLimit.max,
message: 'Too many requests from this IP, please try again later.',
standardHeaders: true,
legacyHeaders: false,
});
app.use('/api', limiter);
// Body parsing middleware
app.use(express.json({ limit: '10mb' }));
app.use(express.urlencoded({ extended: true, limit: '10mb' }));
// Request logging middleware
app.use((req: Request, _res: Response, next) => {
logger.info('Incoming request', {
method: req.method,
path: req.path,
ip: req.ip,
});
next();
});
// Health check endpoint
app.get('/health', (_req: Request, res: Response) => {
res.status(200).json({
status: 'ok',
timestamp: new Date().toISOString(),
uptime: process.uptime(),
environment: environment.nodeEnv,
});
});
// API routes
import authRoutes from './routes/auth.routes';
import userRoutes from './routes/user.routes';
app.use('/api/auth', authRoutes);
app.use('/api/user', userRoutes);
// 404 handler
app.use(notFoundHandler);
// Error handling middleware (must be last)
app.use(errorHandler);
export default app;