1

我在使用 http-proxy-middleware的create-react-app中使用高级代理。我想通过域并仅为所有请求修改端口。

我相信 create-react-app 我必须使用简写:

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

有没有办法可以将所有请求传递给 API,以便域保持不变但端口为 8000?

4

1 回答 1

1

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.

于 2018-12-24T16:59:39.303 回答