Reputation: 4302
I have a node azure function with the function.json like this:
{
"disabled": false,
"bindings": [
{
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [ "get" ]
},
{
"name": "res",
"type": "http",
"direction": "out"
}
]
}
I want the function to return html to give me a page like this:
However, when I write the index.js like this:
module.exports = function (context, sentimentTable) {
context.res = {
body: "<!DOCTYPE html> <html> <head> </head> <body> Hello World </body> </html>",
contentType: "text/html"
};
context.done();
};
I am getting this:
Can Azure Functions return html?
Upvotes: 1
Views: 1409
Reputation: 2724
Alternatively, you can use the fluent express style:
module.exports = function (context, req) {
context.res
.type("text/html")
.set("someHeader", "someValue")
.send("<!DOCTYPE html> <html> <head> </head> <body> Hello World </body> </html>");
};
Make sure that the http output binding is set to res
and not $return
.
Upvotes: 3
Reputation: 6121
Must be 'Content-Type' and you specify headers this way
context.res = {
body: '...',
headers: {
'Content-Type': 'text/html; charset=utf-8'
}
}
See this blog post on AzureServerless.com - http://azureserverless.com/2016/11/12/a-html-nanoserver/
Upvotes: 7