feat: add custom server

This commit is contained in:
nafees nazik
2023-10-14 13:20:27 +05:30
parent 1b24a9b6e9
commit 2c011b7d53

View File

@ -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();