-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (59 loc) · 2.08 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Libraries */
/*---------------------------*/
const express = require('express');
const expressSession = require('express-session');
const expressLayouts = require('express-ejs-layouts');
const dotenv = require('dotenv').config({ path: './config/.env' });
const cookieParser = require('cookie-parser');
const helmet = require('helmet');
const path = require('path');
const redisStore = require('connect-redis')(expressSession);
const chalk = require('chalk');
const logSymbols = require('log-symbols');
const cache = require('./app/db/redis/cache');
/* Init express */
/*---------------------------*/
const app = express();
/* Middlewares */
/*---------------------------*/
app.use(expressLayouts);
app.use(helmet.noCache());
app.use(helmet.frameguard());
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
/* Shortcut path's */
/*---------------------------*/
app.use('/dist', express.static('dist'));
app.use('/img', express.static('dist/img'));
app.use('/css', express.static('dist/css'));
app.use('/js', express.static('dist/js'));
app.use('/logs', express.static('dist/logs'));
app.use('/assets', express.static('src/assets'));
app.use('/', express.static(__dirname));
/* Express session configuration */
/*---------------------------*/
app.use(expressSession({
secret: 'very very secret',
resave: true,
saveUninitialized: false,
store: new redisStore({
host: process.env.REDIS_HOST !== 'null' ? process.env.REDIS_HOST : '127.0.0.1',
port: process.env.REDIS_PORT !== 'null' ? process.env.REDIS_PORT : '6379'
})
}));
/* Express view configuration */
/*---------------------------*/
app.set('view engine', 'ejs');
app.set('view cache', false);
app.set('views', [path.join(__dirname, 'dist/views')]);
/* Application routes */
/*---------------------------*/
app.use(require('./app/routes'));
/* Express server initialize */
/*---------------------------*/
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
cache.delete('cache:watch');
console.log(logSymbols.success, chalk.green('Ready! Listening to: http://localhost:' + PORT));
});