2026-01-31 22:15:01 +01:00
|
|
|
import next from "next";
|
|
|
|
|
import express from "express";
|
|
|
|
|
import {mountApi} from "./api";
|
2026-02-01 21:14:35 +01:00
|
|
|
import http from "http";
|
2026-01-31 22:15:01 +01:00
|
|
|
|
|
|
|
|
const port = Number(process.env.PORT) || 8887;
|
|
|
|
|
const dev = process.env.NODE_ENV !== "production";
|
|
|
|
|
|
|
|
|
|
async function start() {
|
|
|
|
|
const nextApp = next({
|
|
|
|
|
dev,
|
2026-02-01 15:53:50 +01:00
|
|
|
hostname: "0.0.0.0",
|
|
|
|
|
turbopack: dev,
|
|
|
|
|
port
|
2026-01-31 22:15:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const handle = nextApp.getRequestHandler();
|
|
|
|
|
|
|
|
|
|
await nextApp.prepare();
|
|
|
|
|
|
2026-02-01 21:14:35 +01:00
|
|
|
const app = express();
|
2026-01-31 22:15:01 +01:00
|
|
|
|
2026-02-01 21:14:35 +01:00
|
|
|
app.use((req, res, next) => {
|
|
|
|
|
req.setTimeout(0);
|
|
|
|
|
res.setTimeout(0);
|
|
|
|
|
next();
|
|
|
|
|
});
|
2026-01-31 22:15:01 +01:00
|
|
|
|
2026-02-01 21:14:35 +01:00
|
|
|
mountApi(app);
|
|
|
|
|
|
|
|
|
|
app.use((req, res, next) => {
|
2026-01-31 22:15:01 +01:00
|
|
|
if (req.path.startsWith('/services/v1')) return next();
|
|
|
|
|
handle(req, res).catch((err) => {
|
|
|
|
|
console.error('Next.js App Router error:', err);
|
|
|
|
|
res.status(500).send('Internal Server Error');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-01 21:14:35 +01:00
|
|
|
const server = http.createServer(app);
|
|
|
|
|
|
|
|
|
|
server.setTimeout(0);
|
|
|
|
|
server.headersTimeout = 0;
|
|
|
|
|
server.requestTimeout = 0;
|
|
|
|
|
server.keepAliveTimeout = 0;
|
|
|
|
|
|
2026-02-01 15:53:50 +01:00
|
|
|
server.listen(port, "0.0.0.0", () => {
|
2026-02-01 21:14:35 +01:00
|
|
|
console.log(`NEXT APP → http://localhost:${port}`);
|
|
|
|
|
console.log(`API → http://localhost:${port}/services/v1`);
|
2026-01-31 22:15:01 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
start();
|