相关疑难解决方法(0)

Firebase托管与动态云功能重写

我在一个名为的函数中的firebase上有一个基于express.js的云函数应用程序api.要使用自定义域,我正在尝试使用Firebase Hosting重写将特定URL路由到该功能.我在这里关注云功能和Firebase托管的官方文档,https: //firebase.google.com/docs/hosting/functions ,并尝试了许多组合,包括以下内容:

"rewrites": [
      {
        "source": "/api/**",
        "function": "api"
      }
    ]

"rewrites": [
      {
        "source": "/api/:path1/:dat1/dat",
        "function": "api/:path1/:dat1/dat"
      }
    ]
"rewrites": [
      {
        "source": "/api/path1/dat1/dat",
        "function": "api"
      }
    ]
"rewrites": [
      {
        "source": "/api/*/*/*",
        "function": "api"
      }
    ]
Run Code Online (Sandbox Code Playgroud)

可悲的是,它似乎不适用于任何可能的组合.我的快递应用程序具有以下我计划使用的GET路径:

'/api/users/:userId/:userData'
'/api/users/:userId/:userData/json'
'/api/users/:userId/'
Run Code Online (Sandbox Code Playgroud)

和其他类似的.:userId和:userData是我的请求中的参数,因为它与express.js一起使用

所需的功能按预期工作

https://my-firebase-app.cloudfunctions.net
Run Code Online (Sandbox Code Playgroud)

但他们没有合作

https://my-app.firebaseapp.com
Run Code Online (Sandbox Code Playgroud)

请告诉我这些应该如何工作以及我做错了什么.

编辑:这是我的云功能导出的示例

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

app.get('/users/:userId/:userData/json', (req, res) => {
    // Do App stuff here
}
// A couple …
Run Code Online (Sandbox Code Playgroud)

express firebase firebase-hosting google-cloud-functions

14
推荐指数
2
解决办法
7907
查看次数

如何在firebase-hosting中配置重写规则以将某些请求路由到云功能?

我有一个使用聚合物2.0和聚合物火力建造的PWA,是我的网络应用程序.我有一个快速应用程序充当云功能(微服务).例:exports.register=functions.https.onRequest(app);

如何添加重写规则来映射说明/fns/register/fns/verify上面的应用程序register.

firebase.json在云功能微服务项目中更新了我的文件,但是当我运行firebase deploy --only functions:register它时说没有公共文件夹来部署托管配置!

{
    "hosting": {
        "rewrites": [{
            "source": "/fns/**", "function": "register"
        }]
    }    
}
Run Code Online (Sandbox Code Playgroud)

在原始Web应用程序中维护重写规则可能是一种选择,但仍然不是理想的恕我直言.如果我要在原始的Web应用程序中执行此操作,我也尝试过,但无法实现.以下是我firebase.json在原始网络应用程序中的更新:

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "build/default/public",
    "rewrites": [
      {
        "source": "/fns/**",
        "function": "register"
      },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

firebase firebase-hosting google-cloud-functions

13
推荐指数
1
解决办法
1万
查看次数