-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
42 lines (33 loc) · 1.17 KB
/
index.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
const express = require('express');
const bodyParser = require('body-parser');
const session = require('express-session');
const helmet = require('helmet');
const pgConnect = require('connect-pg-simple');
/* Make all variables from our .env file available in our process */
require('dotenv').config();
/* Init express */
const app = express();
/* Init helmet and CORS */
app.use(helmet({ contentSecurityPolicy: false }));
/* set view engine */
app.set('view engine', 'ejs');
/* setup middleware and configs */
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
/* setup static files */
app.use(express.static('./public'));
/* session set up */
app.use(session({
store: new (pgConnect(session))({ conString: process.env.DATABASE_URL }),
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: { maxAge: 30 * 24 * 60 * 60 * 1000 }, // 30 days
}));
/* setup routes */
app.use(require('./routes'));
/* Listen on the port for requests */
app.listen(process.env.PORT || 3000, () => {
console.log('Express server listening on port %d in %s mode', process.env.PORT, app.settings.env);
});
module.exports = app;