Skip to content

Instantly share code, notes, and snippets.

/**
* Given we have a regex with one more matching groups.
* The regex should capture those groups from an 'input'
* string and replace the matched values in an 'template'
* string.
*
* Example:
* regex: /([1-9]{8})/([1-9]{8})?/
* input string: '/some-magic/path/12122211/22112211'
* template string: 'http://someurl?adId=$1&adId=$2'
@sveisvei
sveisvei / gist:594292
Created September 23, 2010 20:26 — forked from coreh/gist:594283
var sys = require('sys');
var path = require('path');
var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World!\n');
console.log('servi');
}).listen(1337, "localhost");
// This is a design doc for adding two methods to node via monkey patching
// that I find useful in all the little bits of HTTP glue I make. The point
// is to create a useful abstraction for forwarding requests and linking
// responses. In the most trivial case for building a reverse proxy, but
// see below for other use cases.
// API
http.ServerRequest.prototype.forward(port, host, dataFilter=null)
http.ServerResponse.prototype.attach(requestOrResponse, responseFilter=null, dataFilter=null)
var fs = require('fs');
var url = require('url');
var sys = require('sys');
var http = require('http');
require('./ejs'); // EJS, http://embeddedjs.com/
/*
* Server-side controller methods
*/