This repository was archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.js
More file actions
58 lines (52 loc) · 1.46 KB
/
server.js
File metadata and controls
58 lines (52 loc) · 1.46 KB
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
57
58
const express = require("express");
const helmet = require("helmet");
const path = require("path");
const fs = require("fs");
const app = express();
const analytics = "https://plausible.trackdechets.beta.gouv.fr/";
app.use(
helmet({
frameguard: {
action: "deny",
},
crossOriginEmbedderPolicy: false,
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
connectSrc: [
"'self'",
"https://formations.trackdechets.beta.gouv.fr",
analytics,
],
baseUri: "'self'",
fontSrc: ["'self'", "https:", "data:"],
frameAncestors: "'none'",
frameSrc: [
"youtube.com",
"www.youtube.com",
"*.sibforms.com",
"*.trackdechets.beta.gouv.fr",
],
imgSrc: ["'self'", "data:"],
scriptSrc: [
"'self'",
"'unsafe-inline'",
"stats.data.gouv.fr",
analytics,
],
styleSrc: ["'self'", "https:", "'unsafe-inline'"],
},
},
})
);
const directory = "/" + (process.env.STATIC_DIR || "public");
app.use(express.static(__dirname + directory));
const pathToIndex = path.join(__dirname, directory, "index.html");
const indexContent = fs.readFileSync(pathToIndex, "utf8");
app.get("/*", function (req, res) {
res.send(indexContent);
});
const port = process.env.PORT || 3000;
app.listen(port, function () {
console.log("Trackdechets website listening on", port);
});