0

I am using React for frontend and Python Flask for backend - I am a beginner in React.

I have setup React with a setupProxy; both the react server & flask server are setup in HTTPS with CA signed certificates

my http-proxy-middleware configuration is as below

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

module.exports = function(app) {
    app.use( proxy( '/api/**', { target: 'https://example.com:5000/', logLevel: 'debug', changeOrigin: true } ));
}

when I call the api /api/login from react it should go to https://example.com:5000/api/login However, this call is sent to https://localhost:5000/api/login

the certificates available here pertain to example.com and I get the following error

[HPM] Error occurred while trying to proxy request /api/login from mydomain.com to https://localhost:5000 (ERR_TLS_CERT_ALTNAME_INVALID) (https://nodejs.org/api/errors.html#errors_common_system_errors)

Both React & Flask servers are on the same server for now

how can I configure http-proxy-middleware correctly so that I am reaching example.com:5000 instead of localhost:5000?

2020-08-24 I have done the following and still could not get it to work

  1. Define a new dns name for the same machine and redirect flask to the new name
  2. Changed the hostname of the machine

how & where & why does the middleware proxy change example.com to localhost is still a mystery

DataGuru
  • 757
  • 7
  • 17

1 Answers1

0

I had posted this on the github as an issue and got the following response.

We need to set the environment variable; if we do not set that then localhost will be set by default

you can see more information here https://github.com/chimurai/http-proxy-middleware/issues/464

DataGuru
  • 757
  • 7
  • 17