How to access endpoint from express router in Cloud Functions Shell

半城伤御伤魂 提交于 2020-01-25 06:57:27

问题


(Note: I'm using javascript, not typescript in my Functions)

My Firebase Project has a single 'oauth' function, which has a series of endpoints created through express app/routers.

I don't understand how to run the functions at these endpoints from the Cloud Functions Shell to debug them locally.

Here is my index.js

const twitter = require("./oauth/twitter");
const app = express();
app.use("/signin/twitter", twitter.router);
exports.oauth = functions.https.onRequest(app);

My actual endpoints are in a twitter.js file (and others for other providers)

router.get("/authorize", (req, res) => {...});
router.get("/authorize_callback", (req, res) => {...});
router.get("/deauthorize", (req, res) => {...});

If I run 'firebase functions:shell' in my terminal, it only shows the 'oauth' function.

I would like to access a function such as 'oauth/signin/twitter/authorize' just like I do in the browser after deploying, but I have no idea how to!

Is this possible?


回答1:


I believe this is the documentation you are looking for. Essentially, you can invoke those express-like routes by calling the method (get, post, etc.) within the Cloud Function in the shell like such: functionName.get('/test')



来源:https://stackoverflow.com/questions/58790706/how-to-access-endpoint-from-express-router-in-cloud-functions-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!