【问题标题】:Creating a catch all redirect & a child function redirect创建一个捕获所有重定向和一个子函数重定向
【发布时间】:2018-05-22 20:21:28
【问题描述】:

我的域似乎重定向到 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"
  }
}

【问题讨论】:

标签: firebase firebase-hosting


【解决方案1】:

这里提到https://stackoverflow.com/questions/44959652/firebase-hosting-with-dynamic-cloud-functions-rewrites/45224176#45224176

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

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-24
    • 2018-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-12
    • 2011-01-31
    相关资源
    最近更新 更多