Oren Saldanha
Oren Saldanha

Reputation: 85

Webpack 4 Proxy (How to set up proxy url in webpack 4)

I am basically a webpack newbie and here's the issue I have come accross. I was following a tutorial on how to set up a proxy url in webpack and used this syntax:

proxy: {
  '/api/*': {
    target: 'http://localhost:5000',
    secure: false
  }
},

But this gives me this error!

The tutorial i was following was before webpack 4 came out so I think webpack 4 has some other way of doing it.

Heres what i want to achieve: * I have a webpackdev server on port 8080 and my express backend is listening on port 5000 i want fetch requests like api/ to go to 5000/api instead of 8080/api.

I hope you guys can help

Upvotes: 2

Views: 1845

Answers (1)

Oren Saldanha
Oren Saldanha

Reputation: 85

I fixed this issue with the following code:

devServer: {
  proxy: {
    '/api/*': {
      target: 'http://localhost:5000',
      secure: false
    }
  },
},

Upvotes: 4

Related Questions