Firebase托管重写设置将所有其他URL传递给特定的Cloud Functions

时间:2019-08-15 13:53:00

标签: firebase google-cloud-functions firebase-hosting

我在Firebase Cloud Functions中都托管了NextJS应用程序和express.js API。

这是我的firebase.json

{
    "hosting": {
        "public": "src/public",
        "rewrites": [
            {
                "source": "/user",
                "function": "api"
            },
            {
                "source": "/users",
                "function": "api"
            },
            {
                "source": "**/**",
                "function": "next"
            }
        ]
    },
    "functions": {
        "source": "src/functions"
    }
}

我期望将/user/users重写为api Cloud Function,并将所有其他URL重写为next Cloud Function。但是它没有按我预期的那样工作。每个URL都传递给next/user的{​​{1}} Cloud Function。 而且我需要帮助...

1 个答案:

答案 0 :(得分:1)

尝试下面的代码,您可以在documentation的示例中找到该代码,该示例用于请求不存在的文件或目录,包括我理解的所有其他答复

// Serves index.html for requests to files or directories that do not exist
 "source": "**",
 "function": "next"