1

i want my server to act as a middleware between the client and another server, the problem is that the target server have a dynamic subdomains that changes everytime randomly

i've tried http-proxy-middleware already, it works well with non dynamic targets, but i could't do any better

var options = {
  target: 'https://123.cdn.me', // target host
  changeOrigin: true,
  ws: true,
  pathRewrite: {
   '^/download/': '/'
  }
};

// create the proxy (without context)
var exampleProxy = proxy(options);
app.use('/download', exampleProxy);
`

i need a way to proxify requests from x1.myserver.com, to x1.traget_server.com and x2.myserver.com to x2.traget_server.com with x1,x2 a random values that should work at runtime and be added dynamically

sida disa
  • 43
  • 5

1 Answers1

0

The question is a bit older but i had similar problems and maybe my solution can help somebody.

var optionsLogin = {
logLevel: 'debug',
changeOrigin: true,
target: 'https://standardTarget.com',
router: async function (proxyRequest, path, req) {
    const sub= proxyRequest.headers.sub
    return 'https://' + sub + env.targetAdress
},

};

with the router parameter i was able to rewrite the targetpoint.

  • Welcome to SO! I'm reviewing your answer as a new contributor and would like to offer some feedback on how to make your answer even better. This would be a perfectly fine answer as-is (in my opinion), but one way to improve it would be to explain _why_ the solution you share in your code addresses/solves the problem presented by OP. Another pattern you'll see is to rewrite the original code but with the working solution based on the code sample that you've provided. Keep contributing and great job on your first answer! – Chris Perry Sep 24 '21 at 19:25