From 2c011b7d53b6c46154d3f574da5c8fca8d83735a Mon Sep 17 00:00:00 2001 From: nafees nazik Date: Sat, 14 Oct 2023 13:20:27 +0530 Subject: [PATCH] feat: add custom server --- backend/src/index.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/backend/src/index.ts b/backend/src/index.ts index 08b159d42..020c7a96c 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -87,6 +87,10 @@ import { setup } from "./utils/setup"; import { syncSecretsToThirdPartyServices } from "./queues/integrations/syncSecretsToThirdPartyServices"; import { githubPushEventSecretScan } from "./queues/secret-scanning/githubScanPushEvent"; const SmeeClient = require("smee-client"); // eslint-disable-line +import path from "path"; +import next from "next"; + +const dir = path.join(__dirname, "../../frontend"); const main = async () => { await setup(); @@ -209,6 +213,19 @@ const main = async () => { // server status app.use("/api", healthCheck); + if (process.env.NODE_ENV === "production") { + const nextApp = next({ + dev: false, + dir + }); + const nextHandler = nextApp.getRequestHandler(); + await nextApp.prepare(); + + app.all("*", (req, res) => { + return nextHandler(req, res); + }); + } + //* Handle unrouted requests and respond with proper error message as well as status code app.use((req, res, next) => { if (res.headersSent) return next();