-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.mjs
56 lines (45 loc) · 1.75 KB
/
server.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import express from "express";
import {injectDecoratorServerSide} from "@navikt/nav-dekoratoren-moduler/ssr/index.js";
import path from "path";
import {fileURLToPath} from "node:url";
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename);
// This value is duplicated in src/config because imports are weird
const basePath = "/sosialhjelp/soknad";
const buildPath = path.resolve(__dirname, "build");
const dockerImage = process.env.IMAGE || process.env.NAIS_APP_IMAGE;
console.log("starter søknad fra docker image: ", dockerImage);
console.log(`Dekoratormiljø: ${process.env.DEKORATOR_MILJO}`);
const app = express(); // create express app
app.disable("x-powered-by");
app.use(basePath, express.static(buildPath, {index: false}));
app.get(`${basePath}/internal/isAlive|isReady`, (_, res) => res.sendStatus(200));
app.use(basePath, (req, res, __) => {
injectDecoratorServerSide({
env: process.env.DEKORATOR_MILJO ?? "dev",
filePath: `${buildPath}/index.html`,
params: {
simple: true,
feedback: false,
chatbot: false,
shareScreen: false,
},
})
.then((text) => res.send(text))
.catch((e) => {
console.error(`Failed to get decorator: ${e}`);
res.status(500).send("Det har oppstått en feil. Venligst prøv igjen senere.");
});
});
// start express server on port 8080
app.listen(8080, () => {
console.log("server started on port 8080");
});
process.on("SIGTERM", () => {
console.log("SIGTERM signal received, shutting down");
process.exit(0);
});
process.on("SIGINT", () => {
console.log("SIGINT signal received, shutting down");
process.exit(0);
});