MVP Build
This commit is contained in:
48
backend/src/app.ts
Normal file
48
backend/src/app.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @ai-summary Express app configuration with feature registration
|
||||
* @ai-context Each feature capsule registers its routes independently
|
||||
*/
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import helmet from 'helmet';
|
||||
import { errorHandler } from './core/middleware/error.middleware';
|
||||
import { requestLogger } from './core/middleware/logging.middleware';
|
||||
|
||||
export const app = express();
|
||||
|
||||
// Core middleware
|
||||
app.use(helmet());
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use(requestLogger);
|
||||
|
||||
// Health check
|
||||
app.get('/health', (_req, res) => {
|
||||
res.json({
|
||||
status: 'healthy',
|
||||
timestamp: new Date().toISOString(),
|
||||
environment: process.env.NODE_ENV,
|
||||
features: ['vehicles', 'fuel-logs', 'stations', 'maintenance']
|
||||
});
|
||||
});
|
||||
|
||||
// Import all feature route registrations
|
||||
import { registerVehiclesRoutes } from './features/vehicles';
|
||||
import { registerFuelLogsRoutes } from './features/fuel-logs';
|
||||
import { registerStationsRoutes } from './features/stations';
|
||||
|
||||
// Register all feature routes
|
||||
app.use(registerVehiclesRoutes());
|
||||
app.use(registerFuelLogsRoutes());
|
||||
app.use(registerStationsRoutes());
|
||||
|
||||
// 404 handler
|
||||
app.use((_req, res) => {
|
||||
res.status(404).json({ error: 'Route not found' });
|
||||
});
|
||||
|
||||
// Error handling (must be last)
|
||||
app.use(errorHandler);
|
||||
|
||||
export default app;
|
||||
Reference in New Issue
Block a user