/
webserver.js
64 lines (45 loc) · 1.49 KB
/
webserver.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
54
55
56
57
58
59
60
61
62
63
64
/*!
* Web Server
* MIT Licensed
*/
/**
* Module dependencies.
*/
var express = require('express'),
info = require("./package.json");
//Setup Express
var app = express();
console.log('Node Server Started!');
console.log('Running Version ' + info.version);
//Static files can be served with express' static middleware.
//I usually make a directory for all static files to be served from the "public" folder.
app.use('/', express.static(__dirname + '/', { maxAge: 86400000 /*one-day*/ }));
app.configure(function(){
//The order of which middleware are "defined" using app.use() is very important,
// they are invoked sequentially, thus this defines middleware precedence.
app.use(express.logger({ format: 'dev' }));
app.use(express.cookieParser());
app.use(express.methodOverride());
app.use(express.compress());
app.use(express.responseTime());
//Handle favicon
app.use(express.favicon());
//Log Errors
app.use(function (err, req, res, next) {
console.error(err.stack);
next(err);
});
});
//PROCESS
process.on('uncaughtException', function (err) {
console.log('PROCESS: Caught exception: ' + err);
});
process.on('exit', function() {
console.log('PROCESS: !!!!!EXITED!!!!');
});
//Kick-Start the server
app.listen(
parseInt(info.server.port) || 5050, //PORT
info.server.host || "localhost" //HOSTNAME
);
console.log(['Server running at http://', info.server.host, ':', info.server.port, '/'].join(""));