-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (33 loc) · 961 Bytes
/
server.js
File metadata and controls
42 lines (33 loc) · 961 Bytes
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
var app,
bootable = require('bootable'),
bootableEnv = require('bootable-environment'),
express = require('express'),
winston = require('winston'),
//routes = require('./routes'),
config = require('./config'), //настройки вынесены в config.json
port = config.get('port');
app = bootable(express());
app.phase(bootable.initializers('setup/initializers/'));
app.phase(function(){ require('./fakedata'); });
app.phase(bootableEnv('setup/environments'));
app.phase(bootable.routes('routes/index.js'));
app.phase(function(){
// обработка ошибок
app.use(function(err, req, res, next){
console.log(err.name);
if (err.name == "ValidationError"){
res.send(400, err);
} else {
next(err);
}
});
app.use(function(err, req, res/*, next*/){
res.send(500, err);
});}
)
app.boot(function(err) {
if (err) { throw err; }
app.listen(port, function(){
winston.info('App running on port: ' + port);
});
});