使用nodejs

时间:2019-03-21 06:17:30

标签: node.js firebase google-cloud-platform

我正在尝试将对象列表从GCP存储桶获取到我在firebase中部署的应用程序。它的代码如下:

  

apis.js

const {Storage} = require('@google-cloud/storage');

const storage = new Storage();
const bucketName = 'gs://cloud-dev-setup';

exports.getBucketData = (req, res) => {
    storage.bucket(bucketName).getFiles().then(files => {
        [files] = files;
        let data = [];
        files.forEach(file => {
            data.push(file.name);
        });
        res.send(data);
    }).catch( error => {
        res.send('catch');
    });
}
  

index.js

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

const apis = require('./apis');
const app = express();
app.get('/test', (req, res) => {
    res.send("Hello from Firebase!");
});

app.get('/fileList', apis.getBucketData);

exports.app = functions.https.onRequest(app);
  

firebase.json

{
  "hosting": {
    "public": "public",
    "rewrites": [{
        "source": "**",
        "function": "app"
    }],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

在本地运行时,它会获得对象列表并按预期工作。

但是在部署到Firebase服务器时,出现以下错误:

  

TypeError:stream.destroy不是函数       在onResultSet(/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/paginator/build/src/index.js:245:24)       根据要求(/user_code/node_modules/@google-cloud/storage/build/src/bucket.js:1344:17)       在Util.handleResp(/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/build/src/util.js:141:9)       在retryRequest(/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/build/src/util.js:422:22)       在onResponse(/user_code/node_modules/@google-cloud/storage/node_modules/retry-request/index.js:200:7)       在/user_code/node_modules/@google-cloud/storage/node_modules/teeny-request/build/src/index.js:222:13       在process._tickDomainCallback(internal / process / next_tick.js:135:7)

     

函数执行耗时841 ms,状态为:“崩溃”

     

错误:函数崩溃超出了请求范围函数不能为   被执行。

我一直在参考此GCP page来设置应用。

0 个答案:

没有答案