Last active
August 3, 2017 14:49
-
-
Save ithinkihaveacat/acd289fe70b61c34240edb4e275a03ce to your computer and use it in GitHub Desktop.
Simple Node.js proxy server
This file contains 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
const BASE = "https://beebo.org"; | |
const http = require("http"); | |
const https = require("https"); | |
const URL = require("url").URL; | |
const server = http.createServer((req0, res0) => { | |
const options = new URL(req0.url, BASE); | |
console.log(`${req0.method} ${options.toString()}`); | |
options.headers = req0.headers; | |
const req1 = https.request(options, (res1) => { | |
Object.keys(res1.headers).forEach((h) => | |
res0.setHeader(h, res1.headers[h]) | |
); | |
res1.pipe(res0); | |
}); | |
req0.pipe(req1); | |
}); | |
server.listen(8080, "127.0.0.1"); // listens on 0.0.0.0 by default |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment