How to process paths like /user/:id and /user/:id/report in HTTP Trigger Firebase cloud functions with access to param id ?
I didn't like next solution because all my functions would be part of the one with prefix /api :
const app = require('express')();
exports.api= functions.https.onRequest(app);
app.get('/user/:uid/report', (req, res) => {}):
But i need something like that:
exports['/user/:uid/report'] = functions.https.onRequest((req, res) => {
// ...
});
UPDATE: It's impossible to have wildcards in hosting routes and get params from it
You can use Firebase Hosting on top of Cloud Functions for Firebase to rewrite URLs to suit the path you want. This means you'll have to firebase init
again and add Hosting if it's not already.
In your project firebase.json
you'll have to add a function rewrite to send all requests to hosting /**
to function api
:
{
"hosting": {
"rewrites": [
{
"source": "/**",
"function": "api"
}
]
}
}
When you deploy, you'll be given a hosting URL in the output. Use this instead of your function URL.
And now, with Hosting in front of Functions, you have to ability to set up caching.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With