我是Firebase函数的新手。我正在尝试在新的URL下重定向功能,而不是使用Firebase函数中的默认URL。
我的firebase.json看起来像这样。有没有办法改善“重写”?
{
"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"
}
}
我可以用这种方式编写它吗,每当添加新功能时,它总是位于我预定义的url /功能名称下吗?
答案 0 :(得分:0)
如果您要问是否可以停止重复输入“ api / vi /”,那么这不是一个选择。重写规则在这方面受到限制。您需要在每次重写时在URL中调出路径。
可以使用重写对通向某个特定函数的路径下的所有内容进行通配符,但是在该函数中,您将必须查看URL路径以弄清楚您想对该URL进行什么操作。有些人使用快速应用程序来帮助解决此问题。如果这样做,则即使要更改其功能之一,也必须部署整个功能/应用程序。