Skip to content

Instantly share code, notes, and snippets.

@dstnbrkr
Created February 12, 2011 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstnbrkr/823394 to your computer and use it in GitHub Desktop.
Save dstnbrkr/823394 to your computer and use it in GitHub Desktop.
Launch a webserver anywhere, the current working directory will be the document root
#!/usr/local/bin/node
var
sys = require('sys'),
path = require('path'),
http = require('http'),
paperboy = require('/usr/local/lib/node/paperboy'),
PORT = 8003,
WEBROOT = process.cwd();
http.createServer(function(req, res) {
paperboy
.deliver(WEBROOT, req, res)
.before(function() {
sys.puts('About to deliver: '+req.url);
})
.after(function() {
sys.puts('Delivered: '+req.url);
})
.error(function() {
sys.puts('Error delivering: '+req.url);
})
.otherwise(function() {
res.sendHeader(404, {'Content-Type': 'text/plain'});
res.write('404, Not Found');
res.finish();
});
}).listen(PORT);
console.log("Running at http://127.0.0.1:" + PORT);
console.log("Document Root: " + WEBROOT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment