admin管理员组文章数量:1415484
I'm having a problem using Express middleware with Firebase Functions. In this example a function is hooked to the app() instance like so:
app.get('*', (req, res) => {
res.send(`Hello ${req.user.name}`);
});
exports.authorizedHello = functions.https.onRequest(app);
How do I go about having multiple functions using express middleware?
This is one of the ways I've tried solving it but calling the endpoints returns a 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);
I'm sure I'm just doing it wrong. Could you point me in the right direction?
I'm having a problem using Express middleware with Firebase Functions. In this example a function is hooked to the app() instance like so:
app.get('*', (req, res) => {
res.send(`Hello ${req.user.name}`);
});
exports.authorizedHello = functions.https.onRequest(app);
How do I go about having multiple functions using express middleware?
This is one of the ways I've tried solving it but calling the endpoints returns a 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);
I'm sure I'm just doing it wrong. Could you point me in the right direction?
Share Improve this question asked Mar 23, 2017 at 17:40 Andrey PokrovskiyAndrey Pokrovskiy 2,9362 gold badges14 silver badges10 bronze badges2 Answers
Reset to default 3Consider that the base path of the cloud function uses your export name, so in this case your valid URLs will be:
https://us-central1-<YOURAPP>.cloudfunctions/authorizedHello/authorizedHello
https://us-central1-<YOURAPP>.cloudfunctions/authorizedHello/authorizedBye
https://us-central1-<YOURAPP>.cloudfunctions/authorizedBye/authorizedHello
https://us-central1-<YOURAPP>.cloudfunctions/authorizedBye/authorizedBye
That's why the example uses get('*', ...)
. You should see your URLs displayed after the deploy mand executes.
You have four URLs because your exporting the same Express app twice.
thank you for your great question. Your question is give me a clue for using template engine .Maybe i'm out of topic of your question . BUT , i just wanna share if anyone want to use template engine like Pug . Look my sample codes here.
const functions = require('firebase-functions');
const express = require("express");
const app = express();
app.set("views",__dirname+"/tmp");
app.set("view engine","pug");
app.engine('pug', require('pug').__express);
app.get("/",p3p(p3p.remended),function(req,res){
res.render("index");
});
app.get("/login",p3p(p3p.remended),function(req,res){
res.render("login");
});
exports.main = functions.https.onRequest(app);
And then you can access that to link like this . https://us-central1-[YOURAPP].cloudfunctions/main/ https://us-central1-[YOURAPP].cloudfunctions/main/login
Sorry for bothering your question. But i had to find my question on google like using "How to use template engine to google cloud functions" i never got the right answer .
I'm just happy because of your sample codes in your question . That's inpiring me to do some improvements. Thank you . Sorry for my bad english :)
本文标签: javascriptUsing Express middleware in Firebase Functions HTTPS requestsStack Overflow
版权声明:本文标题:javascript - Using Express middleware in Firebase Functions HTTPS requests - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745233306a2648919.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论