2017-04-25 36 views
4

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

基本上,我有一个功能设置和运行,看起来像一个基本的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(); 
}; 

我试图部署到一个功能的应用程序是使用招摇简单的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 

我不知道的是如何处理module.exports =应用程序时modeul.exports用于建立函数的事情(即module.exports =功能(背景下, req))

+0

一个例子[git-and-nodejs-on-azure-functions](https://michaelheap.com/git-and-nodejs-on-azure-functions/) – GGleGrand

+0

撇开使用azure-function-express你应该当函数容器已经在http端口上侦听时,请去掉app.listen()调用。 – gpilotino

回答

3

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

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

+0

相关https://github.com/yvele/azure-function-express/issues/9#issuecomment-319297131 –

相关问题