Skip to content

Instantly share code, notes, and snippets.

@tranchausky
Created May 15, 2026 09:37
Show Gist options
  • Select an option

  • Save tranchausky/f52a1235e754e1ee066586297c0a8adc to your computer and use it in GitHub Desktop.

Select an option

Save tranchausky/f52a1235e754e1ee066586297c0a8adc to your computer and use it in GitHub Desktop.
Access domain local no need change file hosts
//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