Some checks failed
CI / build-and-test (pull_request) Has been cancelled
- Add missing --space-1 CSS token used by filter and detail components - Fix active nav link losing styles on hover (CSS specificity) - Correct Russian day pluralization (21 день, 22 дня, 25 дней) - Show filter error banner even when stale race data is present - Add cross-env for Windows-compatible npm test - Add global JSON error handler in Express for malformed request bodies - Replace stateless mock DB with in-memory store for correct DELETE/UPDATE behavior Made-with: Cursor
27 lines
880 B
TypeScript
27 lines
880 B
TypeScript
import express, { Request, Response, NextFunction } from "express";
|
|
import cors from "cors";
|
|
import { config } from "./config";
|
|
import healthRouter from "./routes/health";
|
|
import racesRouter from "./routes/races";
|
|
|
|
export function createApp(): express.Express {
|
|
const app = express();
|
|
|
|
app.use(cors({ origin: config.corsOrigin, methods: ["GET", "POST", "PATCH", "DELETE"] }));
|
|
app.use(express.json());
|
|
|
|
app.use(healthRouter);
|
|
app.use(racesRouter);
|
|
|
|
app.use((err: unknown, _req: Request, res: Response, _next: NextFunction) => {
|
|
if (err instanceof SyntaxError && "body" in err) {
|
|
res.status(400).json({ error: "validation_error", details: ["Invalid JSON in request body"] });
|
|
return;
|
|
}
|
|
console.error("[app] Unhandled error:", err);
|
|
res.status(500).json({ error: "unknown_error", details: ["Internal server error"] });
|
|
});
|
|
|
|
return app;
|
|
}
|