-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
83 lines (66 loc) · 2.03 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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
const express = require('express');
const path = require('path');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const createError = require('http-errors');
const config = require('config');
const redis = require("ioredis");
const nocache = require("nocache");
const helmet = require("helmet");
const RedisStore = require('connect-redis').default;
require('dotenv').config()
const redisClient = new redis(process.env.REDIS_URL);
const redisStore = new RedisStore({
client: redisClient,
ttl: 86400
})
const app = express();
app.use(helmet({
contentSecurityPolicy: false,
crossOriginOpenerPolicy: false
}));
app.set('trust proxy', 1);
app.locals.pretty = true;
app.use(nocache());
app.use(logger('dev'));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(session({
secret: 'secret-session-key',
resave: false,
saveUninitialized: true,
store: redisStore
}));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(require('stylus').middleware({ src: __dirname + '/public' }));
app.use(express.static(path.join(__dirname, 'public')));
app.use((req, res, next) => {
res.locals = {
title: 'IPification Showcase',
stage_url: process.env.STAGE_URL,
live_url: process.env.LIVE_URL,
...res.locals,
...config,
baseUrl: `${req.protocol}://${req.headers.host}`,
get_flow_title: (user_flow, default_title) => {
const client = config.clients.find(item => item.user_flow === user_flow);
return client ? client.title : default_title;
}
}
// res.setHeader('Server', 'IPification');
next();
});
const indexRouter = require('./routes/index');
const userRouter = require('./routes/user');
const authRouter = require('./routes/auth');
app.use('/', indexRouter);
app.use('/user', userRouter);
app.use('/auth', authRouter);
// error handler
app.use(function(err, req, res, next) {
next(createError(500, err.message));
});
module.exports = app;