-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
44 lines (37 loc) · 1.18 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
"use strict";
let express = require('express'),
path = require('path'),
favicon = require('serve-favicon'),
logger = require('morgan'),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser');
let index = require('./routes/index'),
autocomplete = require('./routes/api/autocomplete'),
count = require('./routes/api/count'),
api = require('./routes/api');
let app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
.use(logger('dev'))
.use(bodyParser.json())
.use(bodyParser.urlencoded({extended: true}))
.use(cookieParser())
.use(express.static(path.join(__dirname, 'public')))
.use('/', index)
.use('/api/autocomplete', autocomplete)
.use('/api/count', count)
.use('/api', api)
.use(function (req, res, next) {
let err = new Error('Not Found');
err.status = 404;
next(err);
})
.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
res.status(err.status || 500);
res.render('error');
});
module.exports = app;