使用GET方法为Firebase HTTPS使用云功能

use*_*320 1 https get firebase firebase-realtime-database google-cloud-functions

有人能告诉我如何使用firebase-functions.https.onRequest()进行GET方法吗?所以问题是我想要获取url:/ getData/{type}/{id}

我试过了

exports.getProduct = functions.https.onRequest("/getProduct/{type}/{id}",(request, response) =>{});
Run Code Online (Sandbox Code Playgroud)

但它仍然无法正常工作,我可以用的代码片段是https:// firebase-url/getProduct,我不能放一些参数.

Mic*_*igh 7

https功能触发设置没有任何路径匹配出炉的,但是你可以通过使用快速的应用程序(作为一个例子)为您的HTTPS功能实现这一点:

var functions = require('firebase-functions');
var express = require('express');

var app = express();
app.get('/:type/:id', (req, res) => {
  res.send(req.params);
});

exports.getProduct = functions.https.onRequest(app);
Run Code Online (Sandbox Code Playgroud)

通常,您也可以只检查req.url请求,它是相对于函数名称的路径:

var functions = require('firebase-functions');

exports.getProduct = functions.https.onRequest((req, res) => {
  res.send(req.url);
});
Run Code Online (Sandbox Code Playgroud)

另外,在上述功能,GET/getProduct/foo/bar将具有req.url等于/foo/bar.