Update DOCKER-COMPOSE.md to include Drone CI deployment instructions and refactor server logging to dynamically import modules for production and development environments, separating Vite and static file serving logic into distinct files. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ceced2fc-aa46-458d-ba87-ddd4b7bb1518 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/659922a9-0087-461c-90dd-6d9a58b81d4d/ceced2fc-aa46-458d-ba87-ddd4b7bb1518/SBF5OKZ
This commit is contained in:
+27
-3
@@ -1,6 +1,5 @@
|
||||
import express, { type Request, Response, NextFunction } from "express";
|
||||
import { registerRoutes } from "./routes";
|
||||
import { setupVite, serveStatic, log } from "./vite";
|
||||
import { initializeDatabase, closeDatabase } from "./db";
|
||||
|
||||
const app = express();
|
||||
@@ -21,6 +20,13 @@ app.use((req, res, next) => {
|
||||
res.on("finish", () => {
|
||||
const duration = Date.now() - start;
|
||||
if (path.startsWith("/api")) {
|
||||
const formattedTime = new Date().toLocaleTimeString("en-US", {
|
||||
hour: "numeric",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
hour12: true,
|
||||
});
|
||||
|
||||
let logLine = `${req.method} ${path} ${res.statusCode} in ${duration}ms`;
|
||||
if (capturedJsonResponse) {
|
||||
logLine += ` :: ${JSON.stringify(capturedJsonResponse)}`;
|
||||
@@ -30,7 +36,7 @@ app.use((req, res, next) => {
|
||||
logLine = logLine.slice(0, 79) + "…";
|
||||
}
|
||||
|
||||
log(logLine);
|
||||
console.log(`${formattedTime} [express] ${logLine}`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -38,6 +44,22 @@ app.use((req, res, next) => {
|
||||
});
|
||||
|
||||
(async () => {
|
||||
// Dynamically import utilities based on environment
|
||||
let log: (message: string, source?: string) => void;
|
||||
let serveStatic: (app: express.Express) => void;
|
||||
let setupVite: ((app: express.Express, server: any) => Promise<void>) | undefined;
|
||||
|
||||
if (app.get("env") === "development") {
|
||||
const viteModule = await import("./vite");
|
||||
log = viteModule.log;
|
||||
setupVite = viteModule.setupVite;
|
||||
serveStatic = viteModule.serveStatic;
|
||||
} else {
|
||||
const staticModule = await import("./static");
|
||||
log = staticModule.log;
|
||||
serveStatic = staticModule.serveStatic;
|
||||
}
|
||||
|
||||
// Initialize database if using production mode or USE_DB is true
|
||||
if (process.env.NODE_ENV === 'production' || process.env.USE_DB === 'true') {
|
||||
try {
|
||||
@@ -62,7 +84,9 @@ app.use((req, res, next) => {
|
||||
// setting up all the other routes so the catch-all route
|
||||
// doesn't interfere with the other routes
|
||||
if (app.get("env") === "development") {
|
||||
await setupVite(app, server);
|
||||
if (setupVite) {
|
||||
await setupVite(app, server);
|
||||
}
|
||||
} else {
|
||||
serveStatic(app);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user