代码之家  ›  专栏  ›  技术社区  ›  Giovanni

反应/Firebase托管:为什么在页面刷新时要求用户登录?

  •  0
  • Giovanni  · 技术社区  · 7 年前

    我使用firebase数据库将react web应用程序部署到firebase主机。

    在本地运行应用程序时( yarn start )一切如期进行。。。我可以刷新页面,它只会重新加载内容。然而,一旦我将其部署到firebase并尝试采取相同的步骤,web应用程序就会重定向到 https://appengine.google.com 用户必须登录的位置。

    enter image description here

    我正在使用webpack构建应用程序并部署到我正在使用的firebase firebase-tools

    这是一个需要解释的棘手问题,因为我不理解为什么要求用户登录。web应用没有登录(身份验证)功能。

    该网页包包含以下内容:

      output: {
        path: path.resolve(__dirname, 'public'),
        filename: 'bundle.js',
        publicPath: '/'
      },
    
      devServer: {
        historyApiFallback: true,
      },
    

    处理我正在使用的路由 BrowserRouter from react-router-dom :

    import { BrowserRouter, Route, Switch } from 'react-router-dom'
    
    <BrowserRouter>
      <Switch>
        <Route
          exact
          path='/projects'
          component={Projects} />
      </Switch>
    </BrowserRouter>
    

    firebase.json :

    {
      "database": {
        "rules": "rules/rules.json"
      },
      "hosting": {
        "public": "webapp/public",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ],
        "rewrites": [
          {
            "source": "**",
            "function": "webapp"
          }
        ]
      },
      "functions": {
        "predeploy": [
          "npm --prefix \"$RESOURCE_DIR\" run lint"
        ],
        "source": "functions"
      }
    }
    

    提前感谢您!

    1 回复  |  直到 7 年前
        1
  •  1
  •   Giovanni    7 年前

    固定的

    该问题是由重写数组中的函数引起的。这导致firebase尝试加载一个名为webapp的函数。然而,我没有名为webapp的firebase函数。

    为了解决这个问题,我需要 "destination": "/index.html" 代替“function”:“webapp”。因此给了我们以下信息 firebase.json :

    {
      "database": {
        "rules": "rules/rules.json"
      },
      "hosting": {
        "public": "webapp/public",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ],
        "rewrites": [
          {
            "source": "**",
            "destination": "/index.html"
          }
        ]
      },
      "functions": {
        "predeploy": [
          "npm --prefix \"$RESOURCE_DIR\" run lint"
        ],
        "source": "functions"
      }
    }