0

So I'm building a react webapp that calls some methods deployed on a server.

I installed http-proxy-middleware and added the follow under src folder: setupProxy.js

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function (app) {
  app.use(
    '/api',
    createProxyMiddleware({
      target: process.env.API_URL,
      changeOrigin: true,
      pathRewrite: { '^/api': '' }
    })
  );
};

However, things seem to be working fine locally but when I deploy, the APIs seem to return the html page. Moreover, if I add a <noscript> tag, I get the noscript value within the API preview.

I tried few solutions online but it seems I can't really detect what I'm missing.

Any help would be appreicated

Zok
  • 355
  • 2
  • 15
  • How can we reproduce your issue? Please provide a [mvce](https://stackoverflow.com/help/minimal-reproducible-example) – Lin Du Dec 02 '21 at 02:11
  • I guess the information mentioned is enough for anyone who uses proxy to detect what could be missing. The content pasted is simply all my setupProxy.js file. There may be some app.use or app.get Missing here – Zok Dec 02 '21 at 03:39
  • "I guess ... what could be missing." False. We don't see your react tools setup, we don't see how you send requests. One guess on my part, anyway: Your request includes "text/html" in its accept header. React docs states: "The development server will only attempt to send requests without text/html in its Accept header to the proxy." https://create-react-app.dev/docs/proxying-api-requests-in-development/ – Jozef Mikušinec May 27 '22 at 10:50

0 Answers0