gpt4 book ai didi

javascript - 我们可以显示部署到 azure 函数应用程序的 html 页面吗

转载 作者:行者123 更新时间:2023-12-03 03:00:38 25 4
gpt4 key购买 nike

我们可以显示部署到 azure function app 的 html 页面以及 .js 和 .json 文件吗?任何人都可以建议一下吗?

module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');

if (req.body) {
context.res = {
// status: 200, /* Defaults to 200 */
body: "Hello " + req.body.fname +req.body.lname
};
}
else {
context.res = {
status: 400,
body: "Please pass a name on the query string or in the request body"
};
}
context.done();
};

最佳答案

是的,可以。

下面是返回 HTML 的 HTTPTrigger 函数的示例:

const fs = require('fs');
const path = require('path');

module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');

if (req.query.name || (req.body && req.body.name)) {
context.res = {
// status: 200, /* Defaults to 200 */
body: "Hello " + (req.query.name || req.body.name)
};
context.done();

} else {

// Read an HTML file in the directory and return the contents
fs.readFile(path.resolve(__dirname, 'index.html'), 'UTF-8', (err, htmlContent) => {
context.res = {
headers: {"Content-Type": "text/html"},
body: htmlContent
};

context.done();
});

}
};

关于javascript - 我们可以显示部署到 azure 函数应用程序的 html 页面吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49264644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com