【问题标题】:taking the user from localhost:3000 to localhost:3000/auth/google using proxy target is not working使用代理目标将用户从 localhost:3000 带到 localhost:3000/auth/google 不起作用
【发布时间】:2021-01-11 06:07:05
【问题描述】:

当用户点击使用 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/"
    }
  },

【问题讨论】:

    标签: javascript reactjs frontend backend package.json


    【解决方案1】:

    删除你在 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
        )
      );
    };
    

    【讨论】:

      猜你喜欢
      • 2019-07-07
      • 2018-01-04
      • 1970-01-01
      • 1970-01-01
      • 2020-05-21
      • 2019-03-18
      • 2019-08-24
      • 2021-04-02
      • 2020-10-12
      相关资源
      最近更新 更多