-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.js
38 lines (33 loc) · 1.19 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
const express = require('express');
const config = require('config');
const path = require('path');
const favicon = require('serve-favicon');
const morgan = require('morgan');
const cookieParser = require('cookie-parser');
const logger = require('./lib/logger');
// Create express app and export it before requiring routes
const app = express();
module.exports = app;
const web = require('./routes/web');
const api = require('./routes/api');
const common = require('./routes/common');
const error = require('./routes/error');
// View engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
// General app setup
app.use(favicon(path.join(__dirname, 'public', 'favicon.png')));
app.use(morgan(config.get('morgan').format, { stream: logger.stream }));
app.use(express.json());
app.use(express.text());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.locals.config = config;
// Routes setup (order is important)
app.locals.isReady = Promise.all([common, api, web, error]).then((routers) => {
routers.forEach((router) => {
app.use(router);
});
logger.info('Routes are ready');
});