在 Azure Functions 上部署节点应用 [英] Deploying a Node app on Azure Functions
问题描述
我想知道如何在 Azure Functions 上部署 Node.js 应用程序.
I am wondering about how it might be possible to deploy a Node.js app on Azure Functions.
基本上,我有一个函数设置并运行一个基本的 hello world http 示例,如下所示:
Basically, I have a function setup and running a basic hello world http example that looks like:
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 看起来像:
The app I am trying to deploy into a function is a simple moc client that uses swagger (basically takes a request and returns some xml). The app.js looks like:
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))
The thing I am not sure about is how to handle module.exports = app when modeul.exports is used to establish the function (i.e. module.exports = function (context, req))
推荐答案
可以尝试使用azure-function-express 启用您的 swagger 中间件.
You can try to use azure-function-express to enable your swagger middleware.
请注意,某些中间件将无法正常运行(例如,body-parser).这是因为函数 req
不是流 - 它被注入到函数中,并且已经填充了body"属性.
Note that certain middleware will not function correctly (for example, body-parser). This is because the functions req
is not a stream - it is injected into the function with a 'body' property already populated.
这篇关于在 Azure Functions 上部署节点应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!