How to proxy default route ONLY in webpack

Viewed 15

I'm using Webpack 4.0. I have an app that runs on port:3000. This app contains multiple proxes, for instance:

  • localhost:3000/gallery - will proxy to localhost:4000/gallery
  • localhost:3000/forum - will proxy to localhost:4001/forum

Et cetera.

My case is - how can I proxy path "localhost:3000/" to "localhost:4001/forum"? I tried something like:

{
    context: ['/'],
    target: 'http://localhost:4001/forum',
    secure: false,
    changeOrigin: true,
    headers: {
      Connection: 'keep-alive'
    }
  },

but it parses to every other proxy. So in my ideal world:

  • localhost:3000/ - will proxy to localhost:4001/forum
  • localhost:3000/forum - will proxy to localhost:4001/forum
  • localhost:3000/gallery - will proxy to localhost:4000/gallery

How can I do that?

0 Answers
Related