Created
April 17, 2013 17:54
-
-
Save SE7ENSKY/5406355 to your computer and use it in GitHub Desktop.
Cross-Site Proxy draft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http = require "http" | |
proxyToHost = 'www.sandbox.prostoprint.com' | |
server = http.createServer (request, response) -> | |
delete request.headers.host | |
delete request.headers.hostname | |
proxiedRequest = http.request | |
hostname: proxyToHost | |
host: proxyToHost | |
port: 80 | |
path: request.url | |
method: request.method | |
headers: request.headers | |
, (proxiedResponse) -> | |
proxiedResponse.on "data", (chunk) -> | |
response.write chunk, "binary" | |
proxiedResponse.on "end", -> | |
response.end() | |
proxiedResponse.headers['Access-Control-Allow-Origin'] = '*' | |
response.writeHead proxiedResponse.statusCode, proxiedResponse.headers | |
request.on "data", (chunk) -> | |
proxiedRequest.write chunk, "binary" | |
request.addListener "end", -> | |
proxiedRequest.end() | |
server.listen process.env.PORT or 8080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/eagleeye/5415016/6cb042547bd5471db5280540cd41802e8e5abd55