-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (31 loc) · 924 Bytes
/
app.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
if (process.env.NODE_ENV !== 'production') { require('dotenv').config(); }
const createServer = require('auto-sni');
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const routes = require('./routes');
const settings = {
email: process.env.EMAIL,
agreeTos: true,
debug: true,
domains: process.env.DOMAIN,
forceSSL: process.env.SSL_REDIRECT === 'true',
ports: {
http: process.env.HTTP_PORT,
https: process.env.HTTPS_PORT,
},
};
if (process.env.SSL_REDIRECT !== 'true') {
app.use((req, res, next) => {
if (req.protocol === 'http') {
res.redirect(`https://${process.env.DOMAIN}`);
} else {
next();
}
});
}
app.set('view engine', 'hbs');
app.set('views', process.cwd() + '/www');
app.use(bodyParser.json({verify:function(req,res,buf){req.rawBody=buf}})) // eslint-disable-line
routes(app);
createServer(settings, app);