gpt4 book ai didi

Firebase 函数返回 404

转载 作者:行者123 更新时间:2023-12-03 08:31:36 25 4
gpt4 key购买 nike

我正在尝试为 firebase 函数设置自定义域。自定义域已经验证并且工作正常。我的 firebase 函数在 us-central1 下运行:

enter image description here

这是我的登录功能代码:

const functions = require("firebase-functions");
const express = require(`express`);
const cors = require(`cors`);
const admin = require(`firebase-admin`);
admin.initializeApp();

const firestore = admin.firestore();
const appLogin = express();
appLogin.use(cors({origin:true}));

appLogin.post("/", async(req:Request, res:Response)=>{
functions.logger.log(`received`);
const body = req.body;
functions.logger.log(body);
const result = await firestore.collection(DbCollections.USER).add(body);
return res.status(201).send(JSON.stringify({"user_id":result.id}));
});


exports.login = functions.https.onRequest(appLogin);

没什么特别的...

所以,当我在 postman 中使用屏幕截图中的 url 时 - 它工作正常。但我想使用自定义域,如下所示:

https://mydomai.com/api/login

这是我的 firebase.json 托管部分:

  "hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "/api/login",
"function": "login"
}
]
}

但是当我尝试使用自定义域访问 login 时,它会返回 404 ,但没有任何有值(value)的错误消息: enter image description here

enter image description here

有什么想法吗?

最佳答案

重写的不会从函数调用中的 URL 中删除,因此您可能需要更改 appLogin.post("/", ...)appLogin.post("/api/login/", ...)

关于Firebase 函数返回 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64916582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com