Skip to content

Instantly share code, notes, and snippets.

@cjfswd
Last active June 23, 2022 07:41
Show Gist options
  • Save cjfswd/db2ead0d4a8123ca79ff17e41fa1b6d5 to your computer and use it in GitHub Desktop.
Save cjfswd/db2ead0d4a8123ca79ff17e41fa1b6d5 to your computer and use it in GitHub Desktop.
node http proxy
import http from "http";
import httpProxy from "http-proxy"
const port = 80
const proxy = httpProxy.createProxyServer()
http.createServer((req, res) => {
console.log(req.url)
if(/^\/project-gaming/.test(req.url)){
req.url = req.url.replace(/^\/project-gaming/, "")
proxy.web(req, res, {target: 'http://localhost:3001'})
}else{
proxy.web(req, res, {target: 'http://localhost:3000'})
}
}).listen(port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment