forked from fosrl/pangolin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnextServer.ts
31 lines (24 loc) · 831 Bytes
/
nextServer.ts
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 next from "next";
import express from "express";
import { parse } from "url";
import logger from "@server/logger";
import config from "@server/lib/config";
const nextPort = config.getRawConfig().server.next_port;
export async function createNextServer() {
// const app = next({ dev });
const app = next({ dev: process.env.ENVIRONMENT !== "prod" });
const handle = app.getRequestHandler();
await app.prepare();
const nextServer = express();
nextServer.all("*", (req, res) => {
const parsedUrl = parse(req.url!, true);
return handle(req, res, parsedUrl);
});
nextServer.listen(nextPort, (err?: any) => {
if (err) throw err;
logger.info(
`Next.js server is running on http://localhost:${nextPort}`
);
});
return nextServer;
}