-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
53 lines (47 loc) · 1.49 KB
/
app.js
File metadata and controls
53 lines (47 loc) · 1.49 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
const express = require('express');
const http = require('http');
const compression = require('compression');
const helmet = require('helmet');
const cachePolicy = require('./server/app.webcache');
const security = require('./server/app.security');
const session = require('express-session');
const WEBSITE = {
static: 'build/dist',
port: process.env.PORT || 8083,
secret: process.env.SPW_SESSION_SECRET || 'SMHQs7cLAC3x',
http2: process.env.DEVMIND_HTTP2,
};
const app = express()
.enable('trust proxy')
.use(security.rewrite())
.use(session(security.sessionAttributes(WEBSITE.secret)))
.use(compression())
.use(express.urlencoded({extended: false}))
.use(helmet())
//.use(helmet.contentSecurityPolicy(security.securityPolicy()))
.use(security.corsPolicy())
.use(express.static(WEBSITE.static, {setHeaders: cachePolicy.setCustomCacheControl}))
.all('*', security.notFoundHandler());
app.set('port', WEBSITE.port);
http.Server(app)
.listen(WEBSITE.port)
.on('error', onError)
.on('listening', () => {
console.debug('Listening on ' + WEBSITE.port);
console.debug(`Environnement ${process.env.NODE_ENV}`);
});
function onError(error) {
console.error(error);
if (error.syscall !== 'listen') {
throw error;
}
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EADDRINUSE':
console.error('Port is already in use : ' + WEBSITE.port);
process.exit(1);
break;
default:
throw error;
}
}