-
Notifications
You must be signed in to change notification settings - Fork 34
/
server.js
34 lines (28 loc) · 1.09 KB
/
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
28
29
30
31
32
33
34
var util = require('util');
var static = require('./vendor/node-static/lib/node-static');
//
// Create a node-static server to serve the current directory
//
var file = new(static.Server)('.', { cache: 7200, headers: {'X-Hello':'World!'} });
require('http').createServer(function (req, resp) {
req.body = '';
req.addListener('data',function(chunk){
req.body += chunk
})
req.addListener('end', function () {
// Remark: here is an example of a simple router with node-static fallback
if(req.url == '/'){
req.url = "index.html";
}
file.serve(req, resp, function (err, res) {
if (err) { // An error as occured
util.error("> Error serving " + req.url + " - " + err.message);
resp.writeHead(err.status, err.headers);
resp.end();
} else { // The file was served successfully
util.puts("> " + req.url + " - " + res.message);
}
});
});
}).listen(process.ENV.port || 8080);
util.puts("> asciimo is listening on http://127.0.0.1:8080");