I want to setup a basic proxy like the one browser-sync has, for example I want to go to web1.domain1.xyz and it should proxy to web1.domain.xyz (so it's anything.domain1.xyz to anything.domain.xyz)
I got this part working already :
// HTTP Proxy
var simpleHttp = require("http");
var simpleHttpProxy = require("http-proxy");
var simpleProxy = simpleHttpProxy.createServer();
simpleHttp.createServer(function(req,res){
var target = 'http://'+req.headers.host.replace(/domain1.xyz|domain2.xyz|domain3.xyz/gi,'domain.xyz');
simpleProxy.web(req, res, {
rewriteRules: true,
xfwd: true,
toProxy: true,
changeOrigin: true,
hostRewrite: true,
autoRewrite: true,
protocolRewrite: true,
target: target
});
}).listen(4000);
I would also like to be able to point multiple domains at it, for example domain1.com domain2.com domain3.com.
However it doesn't replace the links, I don't know how browser-sync does this, I've been studying https://github.com/BrowserSync/browser-sync/blob/master/lib/server/proxy-server.js and https://github.com/BrowserSync/browser-sync/blob/master/lib/server/proxy-utils.js
I see that they use a custom function to replace the links, however I didn't succeed in implementing their logic.