Skip to content

Instantly share code, notes, and snippets.

@AndreasMadsen
Forked from dominictarr/test-methods.js
Created November 5, 2011 17:03
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 AndreasMadsen/1341775 to your computer and use it in GitHub Desktop.
Save AndreasMadsen/1341775 to your computer and use it in GitHub Desktop.
node-http-proxy methods not working
var http = require('http')
, httpProxy = require('http-proxy');
httpProxy.createServer(function (req, res, proxy) {
//
// Put your custom server logic here
//
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 9000
});
}).listen(8000);
//
// Target Http Server
//
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('method ' + req.method + ' successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
function finish () {
console.log('all done');
}
var methods = require('express/lib/router/methods');
;(function nextMethodRequest() {
var method = methods.shift();
var req = http.request({
host: 'localhost'
, port: 8000
, path: '/'
, method: method
}, function (res) {
res.on('error', function(err) {
throw err;
})
res.on('end', function () {
console.log(method, 'ok');
if (!methods.length) finish();
else nextMethodRequest();
});
});
req.on('error', function(err) {
throw err;
})
req.end();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment