mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-23 05:16:38 +00:00
bootstrapped
This commit is contained in:
36
server/index.ts
Normal file
36
server/index.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import express, { Request, Response } from "express";
|
||||
import next from "next";
|
||||
import { parse } from "url";
|
||||
import environment from "./environment";
|
||||
import logger from "@/server/logger";
|
||||
import helmet from "helmet";
|
||||
import cors from "cors";
|
||||
import unauth from "@server/routers/unauth";
|
||||
|
||||
const dev = environment.ENVIRONMENT !== "prod";
|
||||
const app = next({ dev });
|
||||
const handle = app.getRequestHandler();
|
||||
|
||||
const port = environment.PORT;
|
||||
|
||||
app.prepare().then(() => {
|
||||
const server = express();
|
||||
|
||||
server.use(helmet());
|
||||
server.use(cors());
|
||||
|
||||
const prefix = `/api`;
|
||||
server.use(prefix, express.json(), unauth);
|
||||
|
||||
server.all("*", (req: Request, res: Response) => {
|
||||
const parsedUrl = parse(req.url!, true);
|
||||
handle(req, res, parsedUrl);
|
||||
});
|
||||
|
||||
server.listen(port, (err?: any) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
logger.info(`Server is running on http://localhost:${port}`);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user