更改云功能的HTTP URL

时间:2017-08-31 22:25:50

标签: firebase google-cloud-functions

我正在使用Cloud Functions for Firebase并编写HTTP触发器。我想从以下位置更改功能URL:

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

为:

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

这可能吗?

1 个答案:

答案 0 :(得分:3)

如果要指定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