-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
56 lines (49 loc) · 1.82 KB
/
Copy pathserver.js
File metadata and controls
56 lines (49 loc) · 1.82 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
// ---------------------------------------------------------------------------
// Server del sito di presentazione.
//
// Il compilatore non vive più sul web: è l'applicazione desktop in desktop/.
// Qui resta solo il sito statico in docs/, servito per comodità durante lo
// sviluppo. Essendo statico può stare anche su GitHub Pages, senza server.
// ---------------------------------------------------------------------------
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const DOCS_DIR = path.join(__dirname, 'docs');
const PORT = Number(process.env.PORT) || 3000;
const app = express();
app.disable('x-powered-by');
app.use((req, res, next) => {
res.setHeader('X-Content-Type-Options', 'nosniff');
res.setHeader('X-Frame-Options', 'DENY');
res.setHeader('Referrer-Policy', 'no-referrer');
res.setHeader('Permissions-Policy', 'geolocation=(), microphone=(), camera=()');
// Il sito non carica nulla da terze parti.
res.setHeader(
'Content-Security-Policy',
[
"default-src 'self'",
"script-src 'self'",
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data:",
"connect-src 'self'",
"object-src 'none'",
"base-uri 'none'",
"frame-ancestors 'none'",
].join('; ')
);
next();
});
app.use('/', express.static(DOCS_DIR, {
etag: false,
maxAge: 0,
setHeaders: (res) => {
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
},
}));
// Vecchi indirizzi, da quando il compilatore stava sul web.
app.get(['/docs', '/docs/'], (req, res) => res.redirect(301, '/'));
app.get(['/app', '/app/'], (req, res) => res.redirect(301, '/#scarica'));
app.listen(PORT, '0.0.0.0', () => {
console.log(`sito di presentazione su http://0.0.0.0:${PORT}`);
});