firebase.json中的函数有没有更好的写法"rewrites"?
Is there a better way to write "rewrites" for functions in firebase.json?
我是 Firebase 函数的新手。我正在尝试使用新 url 下的重定向函数,而不是使用 firebase 函数中的默认 url。
我的 firebase.json 看起来像这样。有没有办法改善"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"
}
}
我可以这样写吗,每当我添加一个新功能时,它总是在我预定义的url/function-name下?
如果您询问是否有可能不再需要重复输入 "api/vi/",那不是一个选项。重写规则在这方面是有限的。每次重写都需要在URL中调出路径
可以使用重写来通配特定函数路径下的所有内容,但是在该函数中,您将必须查看 URL 路径以确定您具体想要做什么URL。有些人使用快递应用程序来帮助解决这个问题。如果这样做,即使要更改其选项之一,也必须部署整个 function/app。
我是 Firebase 函数的新手。我正在尝试使用新 url 下的重定向函数,而不是使用 firebase 函数中的默认 url。
我的 firebase.json 看起来像这样。有没有办法改善"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"
}
}
我可以这样写吗,每当我添加一个新功能时,它总是在我预定义的url/function-name下?
如果您询问是否有可能不再需要重复输入 "api/vi/",那不是一个选项。重写规则在这方面是有限的。每次重写都需要在URL中调出路径
可以使用重写来通配特定函数路径下的所有内容,但是在该函数中,您将必须查看 URL 路径以确定您具体想要做什么URL。有些人使用快递应用程序来帮助解决这个问题。如果这样做,即使要更改其选项之一,也必须部署整个 function/app。