-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (40 loc) · 1.1 KB
/
app.js
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
import compression from "compression";
import { createServer } from "node:http";
import express from "express";
import favicon from "express-favicon";
import { dirname as getDirectoryName, resolve as resolvePath } from "node:path";
import { fileURLToPath } from "node:url";
import helmet from "helmet";
process.on("uncaughtException", (err) => {
console.error(err);
process.exit(1);
});
process.on("unhandledRejection", (err) => {
console.error(err);
process.exit(1);
});
const __filename = fileURLToPath(import.meta.url);
const __dirname = getDirectoryName(__filename);
const app = express();
app.use(compression());
app.use(
helmet.contentSecurityPolicy({
useDefaults: true,
directives: {
"script-src": ["'self'", "sbruchmann.me"],
"style-src": null,
},
})
);
app.use(favicon(resolvePath(__dirname, "public", "favicon.png")));
app.use(express.static(resolvePath(__dirname, "public")));
const port = process.env.PORT || 3000;
const server = createServer(app);
server.listen(port, (err) => {
if (err) {
console.error(err);
process.exit(1);
} else {
console.log(`Listening on port ${port}`);
}
});