【问题标题】:How to fix “Cannot GET” Error on Firebase Cloud Functions如何修复 Firebase Cloud Functions 上的“Cannot GET”错误
【发布时间】:2021-04-05 06:16:36
【问题描述】:

我已成功配置我的 Firebase。在我的 firebase 函数文件夹中,我有我编辑过的 index.js。下面是代码:

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

const {
    getAllTodos
} = require('./APIs/todos')

app.get('/todos', getAllTodos);
exports.api = functions.https.onRequest(app);

我还在函数文件夹的 APIs 目录下创建了一个 todos.js 文件。我已经编写了 getAllTodos 函数。

exports.getAllTodos = (request, response) => {
    todos = [
        {
            'id': '1',
            'title': 'greeting',
            'body': 'Hello world from sharvin shah' 
        },
        {
            'id': '2',
            'title': 'greeting2',
            'body': 'Hello2 world2 from sharvin shah' 
        }
    ]
    return response.json(todos);
}

我已成功将其部署到我的 firebase 上。使用生成的ULR查看

https://us-central1-todoapp-f665a.cloudfunctions.net/api

我一直收到一个

无法获取/

我的代码可能有什么问题?我已经检查了与无法获取/错误有关的其他问题,但无济于事。

提前感谢您的帮助。

【问题讨论】:

    标签: reactjs firebase google-cloud-functions


    【解决方案1】:

    /api 是你快递应用的基本路由。您应该添加/todos 以获得预期的响应。

    https://us-central1-todoapp-f665a.cloudfunctions.net/api/todos
    

    【讨论】:

    • 在浏览器中不手动插入“/todos”如何部署?
    猜你喜欢
    • 1970-01-01
    • 2018-06-11
    • 2019-04-11
    • 2018-06-17
    • 2018-01-02
    • 2019-02-04
    • 2018-10-02
    • 1970-01-01
    • 2021-03-02
    相关资源
    最近更新 更多