Google Cloud功能中的Node Express js

时间:2018-05-31 10:10:03

标签: node.js express google-cloud-platform google-cloud-functions

我已经创建了一个expressjs应用程序,并且我尝试将其部署到Google Cloud Functions中。
我自己开发了应用程序,然后按照guide将其附加到gCloud功能服务。 基本上,我在项目的根目录中创建了一个index.js文件

var app = require('./app');

function App(req,res) {
    if (!req.url) {
        req.url = '/';
        req.path = '/';
    }
    return app(req,res);
}

var converter = App;

module.exports = {
    converter
};

PS。我离开了名称转换器以符合指南以进行测试,我会尽快更新它; D

我的项目现在看起来像这样

- myAppProject
--- index.js
--- app.js
--- package.json
--- someFolderWithCode
------ someFile.js

我压缩了代码并使用gCloud控制台(也就是webapp)上传了zip并定义了converter函数,该函数与index.js中导出的函数相同。
问题是我收到了这个错误

Function load error: File index.js or function.js that is expected to define function doesn't exist in the root directory.

我无法理解我错过了什么。

1 个答案:

答案 0 :(得分:1)

我想出了这个问题。
我压缩myAppProject,而我应该压缩其中包含的所有文件。之后,它接受了index.js文件。