Generated
+4
-3
@@ -3931,7 +3931,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/caniuse-lite": {
|
"node_modules/caniuse-lite": {
|
||||||
"version": "1.0.30001660",
|
"version": "1.0.30001717",
|
||||||
|
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001717.tgz",
|
||||||
|
"integrity": "sha512-auPpttCq6BDEG8ZAuHJIplGw6GODhjw+/11e7IjpnYCxZcW/ONgPs0KVBJ0d1bY3e2+7PRe5RCLyP+PfwVgkYw==",
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "opencollective",
|
"type": "opencollective",
|
||||||
@@ -3945,8 +3947,7 @@
|
|||||||
"type": "github",
|
"type": "github",
|
||||||
"url": "https://github.com/sponsors/ai"
|
"url": "https://github.com/sponsors/ai"
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"license": "CC-BY-4.0"
|
|
||||||
},
|
},
|
||||||
"node_modules/canvas": {
|
"node_modules/canvas": {
|
||||||
"version": "2.11.2",
|
"version": "2.11.2",
|
||||||
|
|||||||
+3
-3
@@ -7,9 +7,9 @@
|
|||||||
"debugdev": "NODE_OPTIONS='--inspect' next dev",
|
"debugdev": "NODE_OPTIONS='--inspect' next dev",
|
||||||
"dev:app": "node ./server/server.js",
|
"dev:app": "node ./server/server.js",
|
||||||
"build": "NODE_ENV=production node_modules/next/dist/bin/next build",
|
"build": "NODE_ENV=production node_modules/next/dist/bin/next build",
|
||||||
"start2": "NODE_ENV=production node ./server/server.js",
|
"start2": "NODE_ENV=production node ./server.js",
|
||||||
"start3": "NODE_ENV=production node_modules/next/dist/bin/next start",
|
"start3": "NODE_ENV=production node_modules/next/dist/bin/next start",
|
||||||
"start": "next start",
|
"start": "NODE_ENV=production next start",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
"prisma:generate": "prisma generate"
|
"prisma:generate": "prisma generate"
|
||||||
},
|
},
|
||||||
@@ -105,4 +105,4 @@
|
|||||||
"eslint-plugin-jsdoc": "^48.2.3",
|
"eslint-plugin-jsdoc": "^48.2.3",
|
||||||
"prisma": "^5.0.0"
|
"prisma": "^5.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const appInsights = require("applicationinsights");
|
|||||||
|
|
||||||
const initAppInsights = (instrumentationKey) => {
|
const initAppInsights = (instrumentationKey) => {
|
||||||
if (!instrumentationKey) {
|
if (!instrumentationKey) {
|
||||||
|
console.log("App Insights not configured.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ const initAppInsights = (instrumentationKey) => {
|
|||||||
.setSendLiveMetrics(true)
|
.setSendLiveMetrics(true)
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
|
console.log("App Insights enabled.");
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -24,6 +26,8 @@ const startServer = async (config) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const app = next(serverOptions);
|
const app = next(serverOptions);
|
||||||
|
await app.prepare(); // prepare BEFORE starting the server
|
||||||
|
|
||||||
const handleNextRequests = app.getRequestHandler();
|
const handleNextRequests = app.getRequestHandler();
|
||||||
|
|
||||||
const srv = createServer((req, res) => {
|
const srv = createServer((req, res) => {
|
||||||
@@ -38,22 +42,28 @@ const startServer = async (config) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
// This code catches EADDRINUSE error if the port is already in use
|
|
||||||
srv.on("error", reject);
|
srv.on("error", reject);
|
||||||
srv.on("listening", () => resolve());
|
srv.on("listening", () => resolve());
|
||||||
srv.listen(config.port, config.hostname);
|
srv.listen(config.port, config.hostname);
|
||||||
});
|
});
|
||||||
|
|
||||||
// It's up to caller to run `app.prepare()`, so it can notify that the server
|
// Graceful shutdown handling
|
||||||
// is listening before starting any intensive operations.
|
process.on("SIGTERM", () => {
|
||||||
|
console.log("Received SIGTERM, shutting down gracefully...");
|
||||||
|
srv.close(() => {
|
||||||
|
console.log("Server closed.");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// App configuration
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
|
|
||||||
const serverConfig = {
|
const serverConfig = {
|
||||||
hostname: "localhost",
|
hostname: "0.0.0.0", // Required for Azure App Service
|
||||||
port: process.env.PORT || 3000,
|
port: parseInt(process.env.PORT, 10) || 3000,
|
||||||
env: process.env.APP_ENV || process.env.NODE_ENV || "production",
|
env: process.env.APP_ENV || process.env.NODE_ENV || "production",
|
||||||
useAppInsights: initAppInsights(
|
useAppInsights: initAppInsights(
|
||||||
process.env.NEXT_PUBLIC_APPINSIGHTS_INSTRUMENTATIONKEY
|
process.env.NEXT_PUBLIC_APPINSIGHTS_INSTRUMENTATIONKEY
|
||||||
@@ -61,24 +71,20 @@ const serverConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
startServer(serverConfig)
|
startServer(serverConfig)
|
||||||
.then(async (app) => {
|
.then(() => {
|
||||||
console.log(
|
console.log(
|
||||||
`started server on host ${serverConfig.hostname}, port ${serverConfig.port}, env ${serverConfig.env}`
|
`Server ready on http://${serverConfig.hostname}:${serverConfig.port} [${serverConfig.env}]`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (serverConfig.useAppInsights) {
|
if (serverConfig.useAppInsights) {
|
||||||
const duration = Date.now() - startTime;
|
const duration = Date.now() - startTime;
|
||||||
|
|
||||||
appInsights.defaultClient.trackMetric({
|
appInsights.defaultClient.trackMetric({
|
||||||
name: "server startup time",
|
name: "Server Startup Time",
|
||||||
value: duration,
|
value: duration,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await app.prepare();
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error("Server failed to start:", err);
|
||||||
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1922,7 +1922,9 @@ callsites@^3.0.0:
|
|||||||
integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==
|
integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==
|
||||||
|
|
||||||
caniuse-lite@^1.0.30001579, caniuse-lite@^1.0.30001646:
|
caniuse-lite@^1.0.30001579, caniuse-lite@^1.0.30001646:
|
||||||
version "1.0.30001660"
|
version "1.0.30001717"
|
||||||
|
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001717.tgz"
|
||||||
|
integrity sha512-auPpttCq6BDEG8ZAuHJIplGw6GODhjw+/11e7IjpnYCxZcW/ONgPs0KVBJ0d1bY3e2+7PRe5RCLyP+PfwVgkYw==
|
||||||
|
|
||||||
canvas@^2.11.2:
|
canvas@^2.11.2:
|
||||||
version "2.11.2"
|
version "2.11.2"
|
||||||
|
|||||||
Reference in New Issue
Block a user