gpt4 book ai didi

firebase - 更改 Cloud Functions 的 HTTP URL

转载 作者:行者123 更新时间:2023-12-02 17:16:46 24 4
gpt4 key购买 nike

我正在使用 Cloud Functions for Firebase 并编写 HTTP 触发器。我想更改函数 URL 来自:

https://us-central1-[projectID].cloudfunctions.net/helloWorld

到:

https://us-central1-[projectID].cloudfunctions.net/api/helloWorld

这可能吗?

最佳答案

如果您想指定 URL 的路径,则不能使用普通的旧 HTTP 函数。您必须改为创建一个 Express 应用程序并将其移交给 Cloud Functions 进行服务。代码看起来像这样:

const functions = require('firebase-functions');
const express = require('express');
const app = express();

app.get('/helloWorld', (req, res) => {
// your function code here
res.send("hello")
})

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

请注意,/api 来自导出的名称,/helloWorld 来自 app.get 中的路径。

您还必须安装 express模块:

npm install express

关于firebase - 更改 Cloud Functions 的 HTTP URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45990932/

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