Prepare application for production deployment with Docker and PostgreSQL
Integrate PostgreSQL database with Drizzle ORM, implement database migrations, and enhance Dockerfile for production build. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ceced2fc-aa46-458d-ba87-ddd4b7bb1518 Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/659922a9-0087-461c-90dd-6d9a58b81d4d/ceced2fc-aa46-458d-ba87-ddd4b7bb1518/ahHWEFX
This commit is contained in:
+20
-1
@@ -1,7 +1,7 @@
|
||||
import express, { type Request, Response, NextFunction } from "express";
|
||||
import { registerRoutes } from "./routes";
|
||||
import { setupVite, serveStatic, log } from "./vite";
|
||||
import { initializeDatabase } from "./db";
|
||||
import { initializeDatabase, closeDatabase } from "./db";
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
@@ -79,4 +79,23 @@ app.use((req, res, next) => {
|
||||
}, () => {
|
||||
log(`serving on port ${port}`);
|
||||
});
|
||||
|
||||
// Graceful shutdown
|
||||
const gracefulShutdown = async (signal: string) => {
|
||||
log(`${signal} received, closing server gracefully...`);
|
||||
server.close(async () => {
|
||||
log('HTTP server closed');
|
||||
await closeDatabase();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// Force close after 30 seconds
|
||||
setTimeout(() => {
|
||||
console.error('Forced shutdown after timeout');
|
||||
process.exit(1);
|
||||
}, 30000);
|
||||
};
|
||||
|
||||
process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));
|
||||
process.on('SIGINT', () => gracefulShutdown('SIGINT'));
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user