usha kiranmai
usha kiranmai

Reputation: 11

can we display html page which we deployed on to azure functions app

Can we display html page which we deployed on to azure function app along with .js and .json files. Could any one suggest please.

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();
};

Upvotes: 1

Views: 1239

Answers (1)

Aaron Chen
Aaron Chen

Reputation: 9950

Yes, you can.

Here is an example of an HTTPTrigger function which returns HTML:

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();
        });

    }
};

Upvotes: 1

Related Questions