| import express, { type Express } from "express"; |
| import cors from "cors"; |
| import cookieParser from "cookie-parser"; |
| import pinoHttp from "pino-http"; |
| import path from "path"; |
| import { fileURLToPath } from "url"; |
| import router from "./routes"; |
| import openaiRouter from "./routes/openai"; |
| import publicRouter from "./routes/public"; |
| import accountsRouter from "./routes/accounts"; |
| import { logger } from "./lib/logger"; |
|
|
| const __filename = fileURLToPath(import.meta.url); |
| const __dirname = path.dirname(__filename); |
|
|
| 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(cors({ credentials: true, origin: true })); |
| app.use(cookieParser()); |
| app.use(express.json({ limit: "20mb" })); |
| app.use(express.urlencoded({ extended: true, limit: "20mb" })); |
|
|
| app.use("/api/public", publicRouter); |
| app.use("/api/admin/accounts", accountsRouter); |
| app.use("/api", router); |
| app.use("/v1", openaiRouter); |
| app.use("/api/v1", openaiRouter); |
|
|
| |
| const frontendDistPath = path.join(__dirname, "../../image-gen/dist/public"); |
| app.use(express.static(frontendDistPath)); |
|
|
| |
| app.use((req, res) => { |
| res.sendFile(path.join(frontendDistPath, "index.html")); |
| }); |
|
|
| export default app; |
|
|