1

I'm following this tutorial to make my React app (localhost:3000) communicate with Node server (localhost:5000) .. so instead of typing <Link to='localhost:5000/auth/google'>Login with Google</Link> I only want it to be just '/auth/google', but when I click on the button with Link tag it sends this error "No routes matched location "/auth/google"
I'm using React v17.0.2

this is what's inside my setupProxy.js file

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

module.exports = function (app) {
  app.use(
    ["/auth/google", /api/*],
    createProxyMiddleware({
      target: "http://localhost:5000",
      changeOrigin: true,
    })
  );
};

the weird thing though is that I got no error when I type the route directly in the browser (both ports work just fine) and it redirect me to the page I want (handled by Express)

If there's no solution for this problem for now, is there any other way to use a proxy in a MERN application because from what I know adding "proxy" in package.json is not working anymore

TylerH
  • 20,799
  • 66
  • 75
  • 101
Hanniballs
  • 31
  • 2
  • Proxies are used to ***proxy*** network/API requests to a server, not navigate outside your app. If using `react-router-dom` and do something like `Login` this can ***only ever*** be interpreted as an internal navigation to an `"/auth/google"` route in the app. – Drew Reese Jan 07 '22 at 17:24

0 Answers0