小编A.k*_*urt的帖子

使用 CORS 测试 Firebase HTTPS 调用

我正在尝试为我的 firebase 云功能设置本地测试环境。但是,当我尝试对我的 HTTP 函数之一进行虚假调用时遇到了问题。

我的错误的原因似乎是我正在使用 CORS (npm)。当我删除 cors 并仅使用 response.status(200) 运行下面看到的函数“test”时,一切正常。但是当用 cors(req,res) 包装时,我的测试失败了 TypeError: Cannot read property 'origin' of undefined。

我在这里做错了什么?

在 index.js -->

exports.test = functions.https.onRequest((request, response) => {

cors(request, response, () => {
    response.status(200);
    response.send("test ok");
})
Run Code Online (Sandbox Code Playgroud)

在我的 test.js 中

describe('Cloud Functions', () => {
    // [START stubConfig]
    var myFunctions, configStub, adminInitStub, functions, admin, cors;

    before(() => {
        // Since index.js makes calls to functions.config and admin.initializeApp at the top of the file,
        // we need to …
Run Code Online (Sandbox Code Playgroud)

javascript mocha.js cors firebase chai

5
推荐指数
1
解决办法
1231
查看次数

标签 统计

chai ×1

cors ×1

firebase ×1

javascript ×1

mocha.js ×1