Skip to content

Instantly share code, notes, and snippets.

@andrewvc
Created April 6, 2010 22:44

Revisions

  1. andrewvc created this gist Apr 6, 2010.
    25 changes: 25 additions & 0 deletions PaperboyDelegateExample.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    http.createServer(function(req, res) {
    var ip = req.connection.remoteAddress;
    paperboy
    .deliver(WEBROOT, req, res)
    .addHeader('Expires', 300)
    .addHeader('X-PaperRoute', 'Node')
    .before(function() {
    sys.log('Recieved Request')
    })
    .after(function(statCode) {
    res.write('Delivered: '+req.url);
    log(statCode, req.url, ip);
    })
    .error(function(statCode,msg) {
    res.writeHead(statCode, {'Content-Type': 'text/plain'});
    res.write("Error: " + statCode);
    res.close();
    log(statCode, req.url, ip, msg);
    })
    .otherwise(function(err) {
    var statCode = 404;
    res.writeHead(statCode, {'Content-Type': 'text/plain'});
    log(statCode, req.url, ip, err);
    });
    }).listen(PORT);