我在使用Express中间件和Firebase函数时遇到问题。在这种example功能被钩到应用程序()实例,像这样:在Firebase函数中使用Express中间件HTTPS请求
app.get('*', (req, res) => {
res.send(`Hello ${req.user.name}`);
});
exports.authorizedHello = functions.https.onRequest(app);
如何去使用快递中间件具有多种功能?
这是我试图解决它,但调用终端的一种方式返回404:
app.get('/authorizedHello', (request, response) => {
response.send(`Hello ${request.user.name}`);
})
app.get('/authorizedBye', (request, response) => {
response.send(`Bye ${request.user.name}`);
})
exports.authorizedHello = functions.https.onRequest(app);
exports.authorizedBye = functions.https.onRequest(app);
我敢肯定,我只是做是错误的。你能指出我正确的方向吗?
谢谢指点/ authorizedHello/authorizedHello工作!后续问题。有没有办法避免在API调用中有两次函数名? –
我建议只做一些像'exports.api = functions.https.onRequest(app);'一次。或'exports.authorized'然后'get('/ hello',...)''get('/ bye',...)' –
或者你可以制作两个不同的快递应用程序并允许'get('*' ,...)'。在我的回答中还澄清说,您目前有四个有效的网址。 –