File size: 1,259 Bytes
ccc21f3 e21e562 d5e788c ccc21f3 e21e562 ccc21f3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import express, { type Express, type Request, type Response } from "express";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { existsSync } from "node:fs";
import compression from "compression";
import cors from "cors";
import pinoHttp from "pino-http";
import router from "./routes";
import { logger } from "./lib/logger";
const app: Express = express();
app.use(pinoHttp({ logger, serializers: { req(req) { return { id: req.id, method: req.method, url: req.url?.split("?")[0] }; }, res(res) { return { statusCode: res.statusCode }; } } }));
app.use(compression());
app.use(cors());
app.use(express.json({ limit: "5mb" }));
app.use(express.urlencoded({ extended: true }));
app.use("/api", router);
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const staticDir = path.join(__dirname, "..", "..", "fb-publisher", "dist", "public");
if (existsSync(staticDir) && existsSync(path.join(staticDir, "index.html"))) {
console.log(`✅ Serving static files from: ${staticDir}`);
app.use(express.static(staticDir));
app.use((_req: Request, res: Response) => { res.sendFile(path.join(staticDir, "index.html")); });
} else {
console.warn(`⚠️ Static dir not found at: ${staticDir}`);
}
export default app; |