| 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; |