我想知道如何在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))
一个例子[git-and-nodejs-on-azure-functions](https://michaelheap.com/git-and-nodejs-on-azure-functions/) – GGleGrand
撇开使用azure-function-express你应该当函数容器已经在http端口上侦听时,请去掉app.listen()调用。 – gpilotino