繁体   English   中英

在Azure Functions上部署节点应用程序

[英]Deploying a Node app on Azure Functions

我想知道如何在Azure Functions上部署Node.js应用程序。

基本上,我有一个功能设置并运行一个基本的hello world http示例,如下所示:

module.exports = function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');
    context.res = {
        // status: 200, /* Defaults to 200 */
        body: "Hello " + req.params.name
    };
    context.done();
};

我试图部署到一个函数的应用程序是一个使用swagger的简单moc客户端(基本上接受请求并返回一些xml)。 app.js看起来像:

const SwaggerExpress = require('swagger-express-mw');
const app = require('express')();
const compression = require('compression');

const configSwagger = {
    appRoot: __dirname, // required config
};


SwaggerExpress.create(configSwagger, (err, swaggerExpress) => {
    if (err) {
        throw err;
    }

    // install middleware
    swaggerExpress.register(app);

    // server configuration
    const serverPort = process.env.PORT || 3001;
    app.listen(serverPort, () => {
        //logger.info('Listening on port %s', serverPort);
    });

    app.use(compression());
});

module.exports = app; // for testing

我不确定的是当modeul.exports用于建立函数时如何处理module.exports = app(即module.exports = function(context,req))

您可以尝试使用azure-function-express来启用您的swagger中间件。

请注意,某些中间件无法正常运行(例如,正文解析器)。 这是因为函数req不是一个流 - 它被注入到函数中,并且已经填充了“body”属性。

暂无
暂无

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

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