admin管理员组

文章数量:1023138

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.

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.

本文标签: javascriptFirebase Functions ExpressHow to get URL params with pathsStack Overflow