This repository has been archived by the owner on Aug 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
80 lines (70 loc) · 1.84 KB
/
server.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require('dotenv').config();
const {
join,
} = require('path');
const express = require('express');
const compression = require('compression');
const bodyParser = require('body-parser');
const helmet = require('helmet');
const nextjs = require('next');
const {
socialRedirect,
contact,
} = require('./lib/telegram');
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = nextjs({
dev,
});
const handle = app.getRequestHandler();
async function startServer() {
await app.prepare();
const server = express();
server.use(helmet());
// server.use(helmet.contentSecurityPolicy({
// directives: {
// defaultSrc: ["'self'"],
// scriptSrc: [
// "'self'",
// "'unsafe-inline'",
// 'www.googletagmanager.com',
// 'www.google.com',
// 'www.gstatic.com',
// 'api.keen.io',
// 'githy.com',
// 'platform.twitter.com',
// ],
// connectSrc: ["'self'", 'www.googletagmanager.com', 'api.keen.io'],
// styleSrc: ["'self'", "'unsafe-inline'"],
// },
// }));
server.use(compression());
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({
extended: true,
}));
server.use((req, res, next) => {
res.setHeader('X-Powered-By', 'The Force');
res.setHeader('X-Why-Would-You-Even-Look-Here', 'No, but for real?');
next();
});
server.use(
'/static',
express.static(`${__dirname}/static`, {
maxAge: '30d',
immutable: true,
}),
);
server.use('/service-worker.js', (req, res) => {
const filePath = join(__dirname, '.next/service-worker.js');
app.serveStatic(req, res, filePath);
});
server.get('/_/:social', socialRedirect);
server.post('/contact', contact);
server.get('*', (req, res) => handle(req, res));
server.listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`);
});
}
startServer();