Azure Functions:NodeJS - HTTP 响应呈现为 XML 而不是 HTML

Azure Functions: NodeJS - HTTP Response Renders as XML rather than HTML

我有一个带有 function.json 的节点 azure 函数,如下所示:

{
  "disabled": false,
  "bindings": [
    {
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [ "get" ]
    },
    {
      "name": "res",
      "type": "http",
      "direction": "out"
    }
  ]
}

我希望函数 return html 给我一个这样的页面:

然而,当我这样写 index.js 时:

module.exports = function (context, sentimentTable) {
    context.res = {
        body: "<!DOCTYPE html> <html> <head> </head> <body> Hello World </body> </html>",
        contentType: "text/html"
    };

    context.done();
};

我得到这个:

Azure Functions return html 可以吗?

必须是'Content-Type'并且你指定headers这样

context.res = {
    body: '...',
    headers: {
        'Content-Type': 'text/html; charset=utf-8'
    }
}

在 AzureServerless.com - http://azureserverless.com/2016/11/12/a-html-nanoserver/

上查看此博客 post

或者,您可以使用流畅的表达方式:

module.exports = function (context, req) {
    context.res
        .type("text/html")
        .set("someHeader", "someValue")
        .send("<!DOCTYPE html> <html> <head> </head> <body> Hello World </body> </html>");
};

确保将 http 输出绑定设置为 res 而不是 $return