Skip to content

Instantly share code, notes, and snippets.

@booo
Created May 7, 2012 18:10
Show Gist options
  • Select an option

  • Save booo/2629384 to your computer and use it in GitHub Desktop.

Select an option

Save booo/2629384 to your computer and use it in GitHub Desktop.
# http forking example
http = require "http"
httpProxy = require "http-proxy"
options =
forward:
port: 9001
host: "localhost"
# proxy on port 8000, forwarding to 9000 and forking to 9001
(httpProxy.createServer 9000, "localhost", options).listen 8000
# http server (backend) on port 9000
(http.createServer (req, res) ->
res.writeHead 200
res.end()
console.log ("#{key}: #{value}" for key, value of req.headers).join "\n"
).listen 9000
# http headers received at backend actual backend
# user-agent: curl/7.21.6 (i686-pc-linux-gnu) libcurl/7.21.6 OpenSSL/1.0.0e zlib/1.2.3.4 libidn/1.22 librtmp/2.3
# host: localhost:8000
# accept: */*
# x-forwarded-for: 127.0.0.1
# x-forwarded-port: 60652
# x-forwarded-proto: http
# connection: keep-alive
# http server (backend) on port 90001
(http.createServer (req, res) ->
res.writeHead 500
res.end()
).listen 9001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment