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

Jam*_*xon 1 azure node.js azure-functions

我有一个节点azure函数与function.json像这样:

{
  "disabled": false,
  "bindings": [
    {
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [ "get" ]
    },
    {
      "name": "res",
      "type": "http",
      "direction": "out"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我希望函数返回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();
};
Run Code Online (Sandbox Code Playgroud)

我得到这个:

在此输入图像描述

Azure函数可以返回html吗?

Ste*_*Lee 6

必须是"Content-Type",您可以通过这种方式指定标题

context.res = {
    body: '...',
    headers: {
        'Content-Type': 'text/html; charset=utf-8'
    }
}
Run Code Online (Sandbox Code Playgroud)

在AzureServerless.com上查看此博客文章 - http://azureserverless.com/2016/11/12/a-html-nanoserver/