Created
May 15, 2026 09:37
-
-
Save tranchausky/f52a1235e754e1ee066586297c0a8adc to your computer and use it in GitHub Desktop.
Access domain local no need change file hosts
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
| //proxy local | |
| //npm install http-proxy | |
| //npm install http-proxy-middleware | |
| //node server.js | |
| //http://demo1.lvh.me:8082 from demo1.lvh.me:8180 of server (server domain need *.lvh.me ) (lvh.me dns default for localhost) | |
| //http://blog.lvh.me:8082 | |
| //http://api.lvh.me:8082 | |
| const http = require('http'); | |
| const httpProxy = require('http-proxy'); | |
| const proxy = httpProxy.createProxyServer({}); | |
| http.createServer((req, res) => { | |
| const host = req.headers.host || ''; | |
| console.log(host); | |
| if (host.includes('demo1.lvh.me')) { | |
| proxy.web(req, res, { | |
| target: 'http://127.0.0.1:8180' | |
| }); | |
| return; | |
| } | |
| if (host.includes('blog.lvh.me')) { | |
| proxy.web(req, res, { | |
| target: 'http://127.0.0.1:8180' | |
| }); | |
| return; | |
| } | |
| if (host.includes('api.lvh.me')) { | |
| proxy.web(req, res, { | |
| target: 'http://127.0.0.1:8000' | |
| }); | |
| return; | |
| } | |
| res.end('not found'); | |
| }).listen(8082, () => { | |
| console.log('proxy running'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment