I'm testing Azure Node Functions locally on my Linux box.
When this is triggered:
module.exports = async function (context, req) {
readFile = require('../SharedCode/readFile.js');
filepath = __dirname + '/../bootstrap-HTML-page/static/simple.html'
fs = require('fs');
fs.readFile(filepath,function(error,content){
if(error) {
content = error;
}
if(content) {
context.res = {
status: 200,
headers: {
'Content-Type': 'text/html'
},
body: content
}
}
})
};
Then I get an empty response.
However if I run this, then I get the expected response:
context.res = {
status: 200,
headers: {
'Content-Type': 'text/html'
},
body: '<html> <body> <h1> test </h1> </body> </html>'
}
I've checked the variable content
and can see my HTML page in there. I can't figure out why it is not responding with the page.
EDIT: I think this is because the built in API fs can't handle promises and you need use something like promisify to make it work as an async function