在Azure函数上部署节点应用程序

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

基本上,我有一个function设置,并运行一个基本的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客户端,使用swagger(基本上接受请求,并返回一些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用于build立function(即module.exports =函数(上下文,请求))

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

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