Forum Discussion

icassiem's avatar
icassiem
Copper Contributor
May 20, 2024

Azure Function App Http Javascript render simple html file to replicate jsrsasign sign certificate

Good day, Please Help.

 

1. In PowerBI im trying to render the javascript sign certificate of jsrsasign, i only got it working via an html file. So im trying to read the html file, simple hello to start of with. Am i better going directly to do the jsrsasign? 

 

2. Locally on VS i got the simple function to return Hello Azure, but trying to read the simple html file executes no error but if i copy in postman i just get a 401 no content found, im not sure how further to debug as in VS i get Ok status, Nothing in Console?

 

Anybody have an example or links plz?

 

const { app } = require('@azure/functions');
const fs = require('fs');
const path = require('path');
app.http('IC5', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    handler: async (request, context) => {
           context.log(`Http function processed request for url "${request.url}"`);
 //       const name = request.query.get('name') || await request.text() || 'world';
 //       return { body: `Hello, ${name}!` };

 //var res = {
    //body: "",
    //headers: {
        //"Content-Type": "text/html"
        //}
    //};

   // readFile = require('../SharedCode/readFile.js');
    //filepath = __dirname + '/test3.html';
    //fs = require('fs');
    //await fs.readFile(filepath,function(error,content){
      
      fs.readFile(path.resolve('./test3.html'), 'UTF-8', (err, htmlContent) => {

        context.res = {
          status: 200,
          headers: {
                'Content-Type': 'text/html'
              },
          body: htmlContent
        }
      
    })
   // if (request.query.name || (request.body && request.body.name)) {      
      //  res.body = "<h1>Hello " + (request.query.name || request.body.name) + "</h1>";
    //} else {      
        //fs.readFile(path.resolve(__dirname,'test3.html'), 'UTF-8', (err, htmlContent) => {
            //res.body= htmlContent;                
            //context.res = res;
        //});
 //   }

    } 
});
//TEST IN POSTMAN: http://localhost:7071/api/IC5?name=hurry

 

No RepliesBe the first to reply

Resources