Sunday, 14 May 2017

http-proxy-middleware not redirecting properly with 302 redirect

I have a browser-sync implementation with a http-proxy-middleware that looks like this:

var proxyAds = proxy('/ad/', { target: 'http://localhost:8000/ad/' });

...

serve({
  port: process.env.PORT || 3000,
  open: false,
  server: {baseDir: root},
  middleware: [
    historyApiFallback(),
    webpackDevMiddleware(compiler, {
      stats: {
        colors: colorsSupported,
        chunks: false,
        modules: false
      },
      publicPath: config.output.publicPath
    }),
    webpackHotMiddleware(compiler),
    proxyAds,
    proxyApi
  ]
});

And inside the /ad/ implementation there is a 302 redirect that takes a parameter to insert as image id

res.writeHead(302, {
    'Location': 'http://placekitten.com/320/200?image=' + n
});

But when I try to go to http://localhost:3000/ad/ instead of redirecting to http://placekitten.com it goes to http://localhost:3000/

http://localhost:8000/ad works correctly and redirects to http://placekitten.com/320/200?image=1



via Tebo

No comments:

Post a Comment