最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firebase Functions Express : How to get URL params with paths - Stack Overflow

programmeradmin0浏览0评论

I have a url in the form www.a/users/uid, I want to get uid.

Assume a function :

exports.smartlink = functions.https.onRequest((req, res) =>

Doing req.params returns an empty array, whereas req.query.uid when the url contains query strings works.

I have a url in the form www.a./users/uid, I want to get uid.

Assume a function :

exports.smartlink = functions.https.onRequest((req, res) =>

Doing req.params returns an empty array, whereas req.query.uid when the url contains query strings works.

Share Improve this question asked Mar 30, 2018 at 11:42 RelmRelm 8,28520 gold badges69 silver badges114 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

If your URL is "www.a./users/uid", "uid" will be part of req.path. You can split that on '/' to get the uid as the last element of the array returned by split.

You can only use req.params with Cloud Functions for Firebase when you're exporting an entire Express app that defines a router that uses a placeholder for the element in the path you want to extract.

Alternatively, you can use express in firebase. and use req.param to get the value.

发布评论

评论列表(0)

  1. 暂无评论