创建捕获所有重定向和子函数重定向

Creating a catch all redirect & a child function redirect

我的域似乎重定向到 index.html 并且所有子链接都很好。
问题是它不会重定向到 api 规则 "source": "/api/**"
我已经使用整个 firebase url(无自定义域)手动检查了 API 并且它有效。

如何让 domain.com/somelink 和 domain.com/api/somelink 联合工作?

配置如下。

firebase.json

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "/api/**",
        "function": "api"
      },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "storage": {
    "rules": "storage.rules"
  }
}

如此处所述

创建一个托管所有其他顶级功能的主应用程序。

const funtions = require('firebase-functions');
const express = require('express');
const app = express();

app.get('/users/:userId/:userData/json', (req, res) => {
    // Do App stuff here
}
// A couple more app.get in the same format

// Create "main" function to host all other top-level functions
const main = express();
main.use('/api', app);

exports.main = functions.https.onRequest(main);

firebase.json

{
    "source": "/api/**", // "**" ensures we include paths such as "/api/users/:userId"
    "function": "main"
}

使用主钩子。

const hooks = express();
main.use('/hooks/, hooks);