-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
executable file
·41 lines (33 loc) · 1.04 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
const debug = require('debug')('server');
const fs = require('fs');
const express = require('express');
const session = require('express-session');
const privateKey = fs.readFileSync('./key/pillaAuth-key.pem', 'utf8');
const certificate = fs.readFileSync('./key/pillaAuth-cert.pem', 'utf8');
const credentials = {
key: privateKey,
cert: certificate,
};
const sessionMW = session({
secret: 'going through hell keep going',
resave: true,
saveUninitialized: true,
//cookie: {maxAge: 60*24*60*60*1000},
});
const app = express();
let server = null;
debug('NODE_ENV %s', process.env.NODE_ENV);
if (process.env.NODE_ENV === 'production') {
server = require('http').createServer(app);
debug('using http...');
} else {
server = require('https').createServer(credentials, app);
debug('using https...');
}
require('./route')(app, sessionMW);
// init websocket services
require('./ws_service')(server, sessionMW);
const port = process.env.PORT || 8080;
server.listen(port, () => {
debug('Server started on port: ' + port);
});