使用 Firebase 到 firebase 函数创建路由

问题描述 投票:0回答:0

我尝试使用 Firebase 函数创建路由。我在

firebase.json
中添加这个:

"rewrites": [
    {
        "source": "/fct1/**",
        "dynamicLinks": true,
        "function": "app"                
    },
    {
        "source": "/fct2/**",
        "dynamicLinks": true,
        "function": "app"                
    }
  ]

这里是

functions/index.js

// Firebase functions
const functions = require("firebase-functions");

// Create an app with Express
const express = require("express");
const app = express();

// Any URL starting with /fct1/id will call this function
app.get("/fct1/:id", (req, res) => {
    res.send("Function 1 | ID = " + req.params.id);
});

// Any URL starting with /fct2/id will call this function
app.get("/fct2/:id", (req, res) => {
    res.send("Function 2 | ID = " + req.params.id);
});

// Export the app
exports.app = functions.https.onRequest(app);

当我访问 URL http://localhost:5000/fct2/12 时出现 404 错误。

怎么了?

firebase express google-cloud-functions firebase-hosting
© www.soinside.com 2019 - 2024. All rights reserved.