简体   繁体   English

具有 Azure 功能的无服务器框架

[英]Serverless Framework with Azure functions

I am writing services with Serverless Framework & Azure Functions .我正在使用Serverless Framework & Azure Functions编写服务。 Examples out there are very simple.那里的例子非常简单。 But when I try to take a step further, I run into problem.但是当我尝试更进一步时,我遇到了问题。 Currently learning from AWS Lambda and then trying to implement it on Azure Functions .目前正在学习AWS Lambda ,然后尝试在Azure Functions上实现它。

The goal of doing so is:这样做的目的是:

1) Implement functions as es6 classes and then building the project with webpack. 1)将函数实现为es6类,然后用webpack构建项目。

2) Find a right project structure, which makes more sense. 2)找到一个合适的项目结构,这更有意义。

3) Follow SoC pattern. 3) 遵循 SoC 模式。

I have created a github project https://github.com/GeekOnGadgets/serverless-azure-settings and when I try to build this project serverless package it creates .serverless folder and inside it there is .zip file (the compiled version).我创建了一个github项目https://github.com/GeekOnGadgets/serverless-azure-settings ,当我尝试构建这个项目serverless package它会创建.serverless文件夹,其中有.zip文件(编译版本)。 Which I understand gets deployed to azure when you run serverless deploy .据我了解,当您运行serverless deploy时,它会被部署到 azure。 But when I check on Azure the function is just development code and not the compiled one (please refer to the code below).但是当我检查 Azure 时,该功能只是开发代码而不是编译代码(请参阅下面的代码)。

Can someone please help with this.有人可以帮忙解决这个问题。 Any suggestions is appreciated.任何建议表示赞赏。

import Settings from './src/Settings/Settings'

module.exports.settings = (event, context, callback) => {
    let settings = new Settings();

    const response = {
        statusCode: 200,
        headers: {
            "Content-Type": "application/json"
        },
        body: JSON.stringify(settings.dev()),
    };
    callback(null, response);
}

Indeed javascript azure functions run on nodejs so commonjs modules are the natural format.实际上,javascript azure 函数在 nodejs 上运行,因此 commonjs 模块是自然格式。 Node also natively supports much of ES6, though the Functions version of node might not be the latest. Node 本身也支持 ES6 的大部分内容,尽管 node 的 Functions 版本可能不是最新的。

however, there is a current speed issue with loading all the dependencies in node_modules.但是,当前在 node_modules 中加载所有依赖项存在速度问题。 This is due to file access so a workaround exists to bundle everything into a single script which package.json -> main points to.这是由于文件访问,因此存在一种变通方法,将所有内容捆绑到 package.json -> main 指向的单个脚本中。

I cant comment on how that fits in with serverless, but perhaps this will help clarify.我无法评论它如何适应无服务器,但也许这将有助于澄清。

As far as I know, Node.js still does not support import/export ES6 syntax for modules.据我所知,Node.js 仍然不支持模块的导入/导出 ES6 语法。 See also here .另请参见此处

Try a new deploy changing from尝试一个新的部署从

import Settings from './src/Settings/Settings'

to

const Settings = require('./src/Settings/Settings')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM