-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (29 loc) · 1.02 KB
/
server.js
File metadata and controls
33 lines (29 loc) · 1.02 KB
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
"use strict";
var paperboy = require('paperboy'),
http = require('http'),
path = require('path');
var webroot = path.join(__dirname, 'dist'),
port = process.env.CHESS_APP_PORT;
http.createServer(function(req, res) {
var ip = req.connection.remoteAddress;
paperboy
.deliver(webroot, req, res)
.addHeader('X-Powered-By', 'Chessimator2000')
.before(function() {
console.log('Request received for ' + req.url);
})
.after(function(statusCode) {
console.log(statusCode + ' - ' + req.url + ' ' + ip);
})
.error(function(statusCode, msg) {
console.log([statusCode, msg, req.url, ip].join(' '));
res.writeHead(statusCode, { 'Content-Type': 'text/plain' });
res.end('Error [' + statusCode + ']');
})
.otherwise(function(err) {
console.log([404, err, req.url, ip].join(' '));
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Error 404: File not found');
});
}).listen(port);
console.log('paperboy on his round on port: ' + port);