feat: stabilize API startup and lifecycle management
- 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.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
const express = require("express");
|
||||
const { checkDatabase } = require("../config/database.lifecycle");
|
||||
const { checkRedis } = require("../config/redis.lifecycle");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
const live = (_req, res) => res.json({
|
||||
status: "ok",
|
||||
service: "zumri-api",
|
||||
timestamp: new Date().toISOString(),
|
||||
uptime: process.uptime(),
|
||||
});
|
||||
|
||||
router.get("/live", live);
|
||||
router.get("/ready", async (_req, res) => {
|
||||
const [database, redis] = await Promise.all([checkDatabase(), checkRedis()]);
|
||||
const ready = database && redis;
|
||||
res.status(ready ? 200 : 503).json({
|
||||
status: ready ? "ready" : "not_ready",
|
||||
checks: { database: database ? "ok" : "error", redis: redis ? "ok" : "error" },
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = { healthRouter: router, live };
|
||||
Reference in New Issue
Block a user