ryanmichaelhirst / passport-react

94 stars 53 forks source link

proxy error #3

Open syedtabeeb1992 opened 3 years ago

syedtabeeb1992 commented 3 years ago

Once i run the project n click on fb/Insta login, it throws an error "Error occured while trying to proxy to: localhost:3000/auth/facebook"

in the console "Proxy error: Could not proxy request /user from localhost:3000 to http://localhost:5000/."

My package.json .. "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject", "server": "nodemon server/index.js", "dev":"concurrently --kill-others \"npm run start\" \"npm run server\" " }, "proxy": "http://localhost:5000/",

setupProxy.js

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

module.exports = function(app) { app.use(proxy('/auth', { target: 'http://localhost:5000/' })); };

`

Avivhdr commented 3 years ago

You probably don't have an .env file and because of that, your server isn't running. See server/index.js :205

You can solve it by doing one of these:

  1. replace this line (205): } else if (process.env.NODE_ENV === "development") { with this line: } else {
  2. add .env file so the src folder with NODE_ENV=development & add require('dotenv').config(); at the top of index.js
HanikJain commented 3 years ago

Update proxy to {createProxyMiddleware}

I faced similar problem with my project and this solution worked for me

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

module.exports = function(app) { app.use(createProxyMiddleware("/auth", { target: "http://localhost:5000" })); };