错误403禁止。无权访问网址

时间:2017-11-19 11:19:55

标签: node.js firebase express url-routing firebase-hosting

我正在尝试迁移到firebase。但在此之前,我通过执行以下操作尝试了一下。我已经成功添加并部署了云功能但是出现了错误

  

错误:禁止

     

您的客户无权从此服务器获取URL / app / lol。

这是在执行以下代码时发生的:

const functions = require('firebase-functions');
const express = require('express');
const app = express()
// tried adding this as middleware
// const cors = require('core'({origin: true}))
var admin = require('firebase-admin');

// app.use(cors)
var serviceAccount = require("./ServiceAccount.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://<my-app>.firebaseio.com/"
});


app.get('/lol', (req, res) => {
    res.send(`${Date.now()}`);
})

exports.site = functions.https.onRequest(app);

我的firebase.json如下:

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "public",
    "rewrites" :[{
      "source" : "**",
      "function" : "app"
      }],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

当我去路线时,它会带我到谷歌认证并在通过正确的帐户签名后。我收到了错误。

这是什么问题!

1 个答案:

答案 0 :(得分:0)

解决的两种替代方法:

  1. 你应该改变

    exports.site = functions.https.onRequest(app); 
    

    exports.app = functions.https.onRequest(app);
    
  2. 你可以修改firebase.json 来自

    "rewrites" :[{
        "source" : "**",
        "function" : "app"
    }],
    

    "rewrites" :[{
        "source" : "**",
        "function" : "site"
     }],