如何从Cloud Functions Shell中的Express路由器访问终结点 [英] How to access endpoint from express router in Cloud Functions Shell

查看:64
本文介绍了如何从Cloud Functions Shell中的Express路由器访问终结点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(注意:我使用的是JavaScript,而不是我的函数中的打字稿)

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

我的Firebase项目具有一个"oauth"功能,该功能具有通过快速应用程序/路由器创建的一系列端点.

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

我不了解如何通过Cloud Functions Shell在这些端点上运行这些功能以在本地对其进行调试.

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

这是我的index.js

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);

我的实际端点在twitter.js文件中(其他端点在其他提供程序中)

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) => {...});

如果我在终端中运行"firebase functions:shell",则仅显示"oauth"功能.

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

我希望像部署后在浏览器中一样访问"oauth/signin/twitter/authorize"之类的功能,但是我不知道该怎么做!

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!

这可能吗?

推荐答案

我相信这是文档.本质上,您可以通过在Shell中的Cloud Function中调用方法(get,post等)来调用类似 express 的路由,例如:functionName.get('/test')

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')

这篇关于如何从Cloud Functions Shell中的Express路由器访问终结点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆