fosrl.pangolin/server/nextServer.ts

32 lines
831 B
TypeScript
Raw Permalink Normal View History

2024-12-07 22:07:13 -05:00
import next from "next";
import express from "express";
import { parse } from "url";
import logger from "@server/logger";
2025-01-01 21:41:31 -05:00
import config from "@server/lib/config";
2024-12-07 22:07:13 -05:00
const nextPort = config.getRawConfig().server.next_port;
2024-12-07 22:07:13 -05:00
export async function createNextServer() {
2024-12-20 22:24:44 -05:00
// const app = next({ dev });
const app = next({ dev: process.env.ENVIRONMENT !== "prod" });
const handle = app.getRequestHandler();
2024-12-07 22:07:13 -05:00
2024-12-20 22:24:44 -05:00
await app.prepare();
2024-12-07 22:07:13 -05:00
2024-12-20 22:24:44 -05:00
const nextServer = express();
2024-12-07 22:07:13 -05:00
2024-12-20 22:24:44 -05:00
nextServer.all("*", (req, res) => {
const parsedUrl = parse(req.url!, true);
return handle(req, res, parsedUrl);
});
2024-12-07 22:07:13 -05:00
2024-12-20 22:24:44 -05:00
nextServer.listen(nextPort, (err?: any) => {
if (err) throw err;
logger.info(
`Next.js server is running on http://localhost:${nextPort}`
);
});
2024-12-07 22:07:13 -05:00
2024-12-20 22:24:44 -05:00
return nextServer;
}