使用Firebase重写将/api/**路由到函数,并将所有其他内容路由到单页应用程序

使用Firebase重写将/api/**路由到函数,并将所有其他内容路由到单页应用程序,firebase,firebase-hosting,Firebase,Firebase Hosting,我已经看到了使用Firebase重写将/api/**路由到Express app函数的其他堆栈溢出解决方案 我遵循这些说明,但也尝试运行一个单页应用程序 由于API路由仍然映射到我的index.html文件,因此将两者结合起来似乎不起作用 这些是我重写的 "rewrites": [ { "source": "/api/**", "function": "api" }, { "source": "**", "destination": "/index.h

我已经看到了使用Firebase重写将/api/**路由到Express app函数的其他堆栈溢出解决方案

我遵循这些说明,但也尝试运行一个单页应用程序

由于API路由仍然映射到我的index.html文件,因此将两者结合起来似乎不起作用

这些是我重写的

"rewrites": [
  {
    "source": "/api/**",
    "function": "api"
  },
  {
    "source": "**",
    "destination": "/index.html"
  }
]

这可能吗

为了回答您的问题,我通过将/api/从单页应用程序规则中排除,成功地做到了这一点

"rewrites": [
  {
    "source": "/api/**",
    "function": "api"
  },
  {
    "source": "!/api/**",
    "destination": "/index.html"
  }
]
这里我们说:

  • 以“/api/”开头的所有内容都将转到名为“api”的函数
  • 其他所有内容都会转到您的单页应用程序(index.html)

您可以发布您的Express功能代码吗?如果您想为多个URL显示相同的内容,请使用重写。