Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何修复&x201C;无法获取”;Firebase云函数出错_Reactjs_Firebase_Google Cloud Functions - Fatal编程技术网

Reactjs 如何修复&x201C;无法获取”;Firebase云函数出错

Reactjs 如何修复&x201C;无法获取”;Firebase云函数出错,reactjs,firebase,google-cloud-functions,Reactjs,Firebase,Google Cloud Functions,我已成功配置firebase。在我的firebase functions文件夹中,有我编辑过的index.js。代码如下: const functions = require('firebase-functions'); const app = require('express')(); const { getAllTodos } = require('./APIs/todos') app.get('/todos', getAllTodos); exports.api = funct

我已成功配置firebase。在我的firebase functions文件夹中,有我编辑过的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);
我还在functions文件夹的API目录下创建了一个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来查看

我不断地得到一份工作

得不到/

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


提前感谢您的帮助。

/api
是您的express应用程序的基本路线。您应该添加
/todo
以获得预期的响应

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

非常感谢。如果不在浏览器中手动插入“/TODO”,如何部署它?