-
Notifications
You must be signed in to change notification settings - Fork 17
/
server.js
27 lines (27 loc) · 820 Bytes
/
server.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
var static = require('node-static'),
http = require('http'),
util = require('util');
var webroot = './files',
port = process.env.PORT || 8080;
var file = new(static.Server)(webroot, {
cache: 600,
headers: { 'X-Powered-By': 'node-static' }
});
http.createServer(function(req, res) {
req.addListener('end', function() {
file.serve(req, res, function(err, result) {
if(err) {
console.error('Error serving %s - %s', req.url, err.message);
if (err.status === 404 || err.status === 500) {
file.serveFile(util.format('/%d.html', err.status), err.status, {}, req, res);
} else {
res.writeHead(err.status, err.headers);
res.end();
}
} else {
console.log('%s - %s', req.url, res.message);
}
});
});
}).listen(port);
console.log('cooper-union-class running at port %d', port);