-
Notifications
You must be signed in to change notification settings - Fork 22
/
web.js
52 lines (37 loc) · 1.17 KB
/
web.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
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const https = require('https');
const app = express();
const router = express.Router();
app.use('/scripts', express.static(`${__dirname}/scripts`));
app.use('/dist', express.static(`${__dirname}/dist`));
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.set('view engine', 'ejs');
app.use(cookieParser());
require('./lib/web')(app);
require('./lib/apis')(router);
app.use('/api', router);
const port = process.env.PORT || 8443;
// if local, use 8443 and certificate
if (process.env.NODE_ENV === 'dev') {
const passPhrase = process.env.PASS_PHRASE;
const certPem = process.env.CERT_PEM.replace(/\\n/g, '\n');
const keyPem = process.env.KEY_PEM.replace(/\\n/g, '\n');
const sslOptions = {
key: keyPem,
cert: certPem,
passphrase: passPhrase
};
const httpsServer = https.createServer(sslOptions, app);
httpsServer.listen(port, () => {
console.log(`Example app listening on port ${port}!`);
});
} else {
app.listen(port, () => {
console.log(`Example app listening on port ${port}!`);
});
}