generated from yandex-praktikum/middle.messenger.praktikum.yandex
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
37 lines (32 loc) · 903 Bytes
/
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
const express = require('express');
const helmet = require('helmet');
const path = require('path');
const app = express();
const port = process.env.PORT || 3000;
app.use(express.static(path.join(__dirname, 'dist')));
app.use(
helmet({
contentSecurityPolicy: {
useDefaults: true,
directives: {
'script-src': ["'self'", "'unsafe-eval'"],
'connect-src': ['ya-praktikum.tech', 'wss://ya-praktikum.tech'],
'img-src': ["'self'", 'data:', 'ya-praktikum.tech'],
'object-src': ["'self'"],
},
},
})
);
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
// eslint-disable-next-line consistent-return
app.use((err, req, res, next) => {
if (res.headersSent) {
return next(err);
}
res.redirect('/500');
});
app.listen(port, () => {
console.log(`The app is running at http://localhost:${port}`);
});