-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (41 loc) · 1.15 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
var express = require('express');
var path = require('path');
require("coffee-script/register")
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var v1Routes = require('./routes/v1');
var admin = require('./routes/admin');
var app = express();
var env = process.env.NODE_ENV || 'development';
app.locals.ENV = env;
app.locals.ENV_DEVELOPMENT = env == 'development';
// app.use(favicon(__dirname + '/public/img/favicon.ico'));
app.use(logger(env));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(cookieParser());
app.use('/v1', v1Routes);
app.use('/', v1Routes);
app.use('/admin', admin);
/// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
/// error handler
// development error handler
// will print stacktrace
app.use(function(err, req, res, next) {
res.status(err.status || 500);
if (app.get('env') === 'development') {
res.send(err.message)
} else {
res.end();
}
});
module.exports = app;