Last active
June 23, 2022 07:41
-
-
Save cjfswd/db2ead0d4a8123ca79ff17e41fa1b6d5 to your computer and use it in GitHub Desktop.
node http proxy
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
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