-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
43 lines (38 loc) · 1.27 KB
/
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
38
39
40
41
42
43
const express = require('express');
require('dotenv/config');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const sessionConfig = require('./config/session');
const ejsLayouts = require('express-ejs-layouts');
const flash = require('connect-flash');
const app = express();
app.use(cookieParser(process.env.ENKY_SECRET_KEY));
app.set('trust proxy', 1); // trust proxie required for https
app.use(session(sessionConfig));
// EJS
app.use(ejsLayouts);
app.set('layout', 'layouts/default');
app.set('view engine', 'ejs');
// Not needed behind a reverse proxy
if (process.env.ENKY_ENV === 'local') {
app.use(express.static('public'));
}
// Express body parser
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// Connect flash
app.use(flash());
// Global variables
app.use(function(req, res, next) {
res.locals.success_msg = req.flash('success_msg');
res.locals.error_msg = req.flash('error_msg');
res.locals.error = req.flash('error');
res.locals.session = req.session;
res.locals.enkyDebug = process.env.ENKY_DEBUG;
// res.locals.debug = true;
next();
});
// Routes
app.use('/', require('./routes/index.js'));
const PORT = process.env.ENKY_PORT || 5000;
app.listen(PORT, console.log(`Enky started on port ${PORT}`));