1

I'm using an advanced proxy in create-react-app which uses http-proxy-middleware. I'd like to pass through the domain and modify the port only for all requests.

I believe in create-react-app I must use the shorthand:

app.use(
  '/api',
  proxy({ target: 'http://www.example.org:8000' })
)

Is there a way I can pass through all requests to API so that the domain is unchanged but the port is 8000?

Toby
  • 12,743
  • 8
  • 43
  • 75

1 Answers1

2

I found that this approach works:

const proxy = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(
    proxy('/api', {
      target: 'https://[::1]:8000',
      secure: false,
    })
  )
}

As a way to proxy https://<any-domain>:3000/api to https://<any-domain>:8000, as mentioned in a few issues on the http-proxy-middleware. However, this seems a little hacky, and I can find no reference to this in the docs.

If anyone has any additional feedback on this, I'd be very interested to read more.

Note that ::1 is just the IPv6 loopback address.

Toby
  • 12,743
  • 8
  • 43
  • 75