-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
68 lines (55 loc) · 1.75 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
const express = require('express');
const config = require('./lib/config');
const logger = require('./lib/logger');
const middleware = require('./middleware');
const redisClient = require('./lib/redis-client');
const setup = (options = {
middlewareSetupFn: undefined
}) => {
if (options.config !== false) config.setup(options.config);
if (options.logs !== false) logger.setup({
...config.get('logs'),
...options.logs
});
if (options.redis !== false) redisClient.setup({
...config.get('redis'),
...options.redis
});
const app = middleware.setup({
...config.get(),
...options
});
if (options.middlewareSetupFn && typeof options.middlewareSetupFn === 'function') {
options.middlewareSetupFn(app);
}
const staticRouter = express.Router();
app.use(staticRouter);
if (options.session !== false) middleware.session(app, {
...config.get('session'),
...options.session
});
const router = express.Router();
app.use(router);
const errorRouter = express.Router();
app.use(errorRouter);
if (options.errors !== false) middleware.errorHandler(app, {
...config.get('errors'),
...options.errors
});
if (options.port !== false) middleware.listen(app, {
port: options.port || config.get('port'),
host: options.host || config.get('host'),
});
return { app, staticRouter, router, errorRouter };
};
module.exports = {
setup,
middleware,
config,
logger,
redisClient,
translation: require('./middleware/translation'),
nunjucks: require('./middleware/nunjucks'),
linkedFiles: require('./middleware/linked-files'),
featureFlag: require('./middleware/feature-flag')
};