2017-02-07 3 views
1

としてレンダリングし、私はこのようなfunction.jsonとノード紺碧の機能があります。Azureの機能:NodeJS - HTTPレスポンスがXMLではなくHTML

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

を私のような機能が私にページを与えるためにHTMLを返すようにしたいですこの:私はこのようなindex.jsを書くしかし enter image description here

、:

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

    context.done(); 
}; 

私はこの取得しています:

enter image description here

Can Azure関数はhtmlを返しますか?

答えて

6

こうして 'のContent-Type' であるとあなたがヘッダを指定する必要があります

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

AzureServerless.comでこのブログ記事を参照してください - http://azureserverless.com/2016/11/12/a-html-nanoserver/

2

また、あなたは流暢急行スタイル使用することができます。

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ではないことを確認してください。

関連する問題