Create React App http-proxy-middleware not working Create React App http-proxy-middleware not working express express

Create React App http-proxy-middleware not working


As of v1.0.0 of http-proxy-middleware, the setupProxy.js file requires an explicit import; so instead of the previous default import

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

You need to use:

const { createProxyMiddleware } = require('http-proxy-middleware');module.exports = function(app) {    app.use(createProxyMiddleware("/api", { target: "http://localhost:3090" }));};


Found the answer to this one - and as expected it was a simple error.

The routes on my express server were as follows:

app.post("/login", requireSignIn, Authentication.login);

Whereas they should have been:

app.post("api/login", requireSignIn, Authentication.login);

Problem solved!


Replace codes of setupProxy.js file as follows:

const { createProxyMiddleware } = require('http-proxy-middleware');module.exports = function(app) {  app.use(    '/api/login',    createProxyMiddleware({      target: 'http://localhost:3090',      changeOrigin: true,    })  );};