Ahm*_*wky 2 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
那可能吗?
如果要指定 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);
Run Code Online (Sandbox Code Playgroud)
请注意,/api它来自导出的名称并/helloWorld来自app.get.
您还必须安装express模块:
npm install express
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1952 次 |
| 最近记录: |