I am new to firebase functions. I am trying redirect functions under a new url instead of using default url from firebase functions.
My firebase.json looks like this. Is there a way to improve "rewrites"?
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
],
"source": "functions"
},
"hosting": {
"cleanUrls": true,
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "/.well-known/acme-challenge/wVJAlodX0whlzQQxznOSngFXGWFOLtsjk2F9l7oQDXc",
"destination": "/firebaseHostingVerification"
},
{
"source": "api/v1/currencies",
"function": "currencies"
},
{
"source": "api/v1/stop",
"function": "stop"
},
{
"source": "api/v1/track",
"function": "track"
},
{
"source": "api/v1/bookmark",
"function": "bookmark"
},
{
"source": "api/v1/authenticate",
"function": "authenticate"
},
{
"source": "api/v1/add-token",
"function": "addUserToken"
},
{
"source": "api/v1/update-history",
"function": "updateHistory"
},
{
"source": "api/v1/update-rates",
"function": "updateLatestRatesWithCodes"
},
{
"source": "api/v1/createMoneyChanger",
"function": "createMoneyChanger"
},
{
"source": "api/v1/moneyChanger",
"function": "moneyChanger"
},
{
"source": "api/v1/updateRates",
"function": "updateRates"
}
//
{
"source": "**",
"destination": "/index.html"
}
]
},
"database": {
"rules": "database.rules.json"
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"storage": {
"rules": "storage.rules"
}
}
Can I write it in such a way, whenever I add a new functions, it is will always be under my predefined url/function-name?
If you're asking if it's possible to stop having to type "api/vi/" repeatedly, that is not an option. The rewrite rules are limited in this respect. You are required to call out the path in the URL for every rewrite.
It is possible to use rewrites to wildcard everything under a path to a specific function, but then in that function, you will have to look at the URL path to figure out what specifically you want to do with that URL. Some people use an express app to help with that. If you do this, you will have to deploy that entire function/app if you want to change even one of its options.