267e80e2ec
- Refactor server initialization to separate concerns and improve error handling. - Implement centralized environment validation using Zod. - Introduce database, Redis, and queue lifecycle management. - Add health check endpoints for liveness and readiness. - Enhance error handling middleware for better response structure. - Implement rate limiting for API endpoints. - Add request ID middleware for traceability. - Create Sequelize CLI configuration and baseline migration for schema management. - Establish CI workflow with Gitea for testing and syntax checks. - Document foundational changes and migration strategy in PHASE_0_FOUNDATION_STABILIZATION.md. - Add Docker Compose configuration for local development and testing. - Implement unit and integration tests for critical functionality.
11 lines
312 B
JavaScript
11 lines
312 B
JavaScript
const { randomUUID } = require("crypto");
|
|
|
|
const SAFE_REQUEST_ID = /^[A-Za-z0-9_-]{8,128}$/;
|
|
|
|
module.exports = (req, res, next) => {
|
|
const supplied = req.get("x-request-id");
|
|
req.id = supplied && SAFE_REQUEST_ID.test(supplied) ? supplied : randomUUID();
|
|
res.setHeader("X-Request-ID", req.id);
|
|
next();
|
|
};
|