使用代理目标将用户从 localhost:3000 转移到 localhost:3000/auth/google 无效

taking the user from localhost:3000 to localhost:3000/auth/google using proxy target is not working

当用户单击“使用 Google 登录”时,用户将被带到 Google OAuth 流程以执行登录过程。但是点击浏览器只是将其 url 更改为 localhost:3000/auth/google 并且没有任何反应。 如果我明确提供完整的 href 即

,它就可以正常工作

http://localhost:5000/auth/google

应用组件:

import './App.css';
import React, { Component } from 'react';
class App extends Component {
  render() {
    return (
      <div className="App">
        <a href="/auth/google">Sign in using google</a>
      </div>
    );
  }
}
export default App;

package.json

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "proxy": {
    "/auth/google": {
      "target": "http://localhost:5000/"
    }
  },

删除您在 package.json 上的代理并试试这个 在你的 src 目录上创建 setupProxy.js 然后 npm install http-proxy-middleware

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

const proxy = require("http-proxy-middleware");
module.exports = function (app) {
  app.use(
    createProxyMiddleware(
      "/auth/google",
     // replace with your endpoint
      { target: "http://localhost:5000" } // replace with your target
    )
  );
};