自定义HTTP路径的Firebase云功能 [英] Cloud Functions for Firebase with custom HTTP path
问题描述
是创建一个休息般的路径系统来访问函数。
我有一个 GitHub 与我的项目,如果有任何疑问。
cloudfunctions.net
域会将所有以函数名开头的流量路由到该函数。所以,例如,你可以用标准的Express应用程序来做到这一点: var functions = require('firebase-functions') ;
var express = require('express');
var app = express();
$ b $ app.post('/ bar',(req,res)=> {
res.end('bar');
});
$ b $ app.get('/ foo',(req,res)=> {
res.end('foo');
});
exports.myFunc = functions.https.onRequest(app);
以上将允许您向 / myFunc / foo
和
/ myFunc / bar
并分别处理。有一点需要注意的是,目前如果您传递一个Express应用程序,如果您尝试访问 / myFunc
中的函数,将会出现错误,而不是需要将您的请求发送到 / myFunc /
(带有斜线)。
Is there a way of defining the HTTP path (after the first '/') to access a Cloud Function for Firebase?
What I'm tying to achieve is to create a rest-like path system to access the functions.
I have a GitHub with my project if there is any doubts.
The cloudfunctions.net
domain will route all traffic beginning with a function name to that function. So, for example, you could do this with a standard Express app:
var functions = require('firebase-functions');
var express = require('express');
var app = express();
app.post('/bar', (req, res) => {
res.end('bar');
});
app.get('/foo', (req, res) => {
res.end('foo');
});
exports.myFunc = functions.https.onRequest(app);
The above will allow you to make requests to /myFunc/foo
and /myFunc/bar
and handle them separately. One thing to note is that currently if you pass an Express app there will be an error if you try to access your function at /myFunc
, instead needing to make your request to /myFunc/
(with a trailing slash).
这篇关于自定义HTTP路径的Firebase云功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!