-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
49 lines (39 loc) · 1.35 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
// Create a "global" object to store references to all the libraries we are using, which we will then pass down into our modules for convenience
var env = {};
// Require all the various modules we use components from
env.express = require('express');
env.path = require('path');
env.favicon = require('serve-favicon');
env.http = require('http');
env.logger = require('morgan');
env.cookieParser = require('cookie-parser');
env.bodyParser = require('body-parser');
env.assert = require('assert');
env.app = env.express();
// Enable dev logging
env.app.use(env.logger('dev'));
// require('./validata.js')(env);
env.app.use(env.express.static(env.path.join(__dirname, 'public')));
env.app.use('/', require('./routes/index'));
// catch 404 and forward to error handler
env.app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (env.app.get('env') === 'development') {
env.app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.status(err.status || 500).send( '<pre>' + err.stack + '</pre>' );
});
}
// production error handler
// no stacktraces leaked to user
env.app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.send( err.message );
});
module.exports = env.app;