问题描述
我无法访问Firebase帐户中的JSON API.我将在终端中输入"firebase deploy",它将返回以下网址
I'm having trouble accessing a JSON api that is inside of my Firebase account. I'll type "firebase deploy" in my terminal and it'll return the following url,
如果我随后将其输入到浏览器中,则会得到 Index.html 页面,因此我知道它通常可以正常工作.但是,由于我正在尝试访问API,所以我搜索URL/api/app,该URL/api/app在运行"firebase serve"时有效,但在运行deploy时却无效.它返回以下
If I then enter it into my browser I get my Index.html page so I know it generally works. But being that I'm trying to access the API I search the URL/api/app which works when I run "firebase serve" but doesn't when I run deploy. It returns the following
但是我的gmail帐户可以在firebase上使用,并且所有内容都可以检出,但firebase&云功能仍然无法让我访问我的API.请帮忙.
however my gmail account is permitted on firebase and everything checks out but firebase & cloud functions still won't let me access my API. Please help.
这是我的代码.
INDEX.JS
const functions = require("firebase-functions");
const server = require(__dirname,"../server.js");
const api = functions
.runWith({ memory: "2GB", timeoutSeconds: 120 })
.https.onRequest(server);
module.exports = {
api
};
SERVER.JS
const express = require("express");
const path = require("path");
const logger = require("./middleware/logger.js");
const cors = require("cors");
const routes = require("./router/routes.js");
let app = express();
// Init Middleware
app.use(logger);
// Set static folder
app.use(express.static(path.join(__dirname, "public")));
app.use(cors({ origin: true }));
app.use("/", routes);
module.exports = app;
FIREBASE.JSON
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "public",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"function": "server"
}
]
}
}
推荐答案
必须在您的GCP控制台上解决.只需执行以下步骤:
It must be solved at your GCP Console. Just follow these steps:
- 转到您的 GCP控制台并登录
- 在顶部菜单上,选择相应的Firebase项目
- 在左侧菜单中转到云功能"
- 单击函数的复选框(而不是函数的名称)
- 选择后,在右侧菜单上选择添加成员"
- 在新成员"上输入allUsers
- 在选择"功能栏上,选择云功能"->云函数调用程序
- 点击保存"然后允许公共访问"在弹出警告上
你很好!!
这篇关于错误:禁止您的客户端没有权限从此服务器获取URL/api/app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!