Issue with Azure functions



  • Hi,

    Sorry, I know I am asking a lot of questions, but I am working on big reports and it's all new to me: jsReport, Azure Functions, handlebars....I am unfamiliar with all these.

    So this my studio, invoice is just a test template:
    alt text

    ALL reports are working fine in the studio.

    and this is the main function that i am calling jsReport:

    /**
     * @function fetchReport  It's the Promise function that sends a post request to jsReport server (using axios)
     * then it pipes the response to a streamObj, the promise is resolved after finishing writing the stream to the temp folder
     * @param {string} path the path to temp folder
     * @param {object} data  The object needed to generate report in jsReport server (a Functions App)
     * @param {string} functionName  The name of the Azure's function in  jsReport app, for now there's only one.
     * @param {string} reportName   it's the name of the report template configured in jsReport.
     */
    
    const fetchReport = (path, data, functionName, reportName) => {
      return new Promise(async (resolve, reject) => {
        let jsr = process.env.JSREPORTURL + "/api/" + functionName;
    
        let options = {
          url: jsr, //valid string to report api
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify(data),
          responseType: "stream",
          maxContentLength: Infinity,
          maxBodyLength: Infinity,
        };
    
        let response = await axios.post(
          jsr,
          {
            template: { name: reportName },
            data: data,
          },
          options
        );
        if(response.data){   
        let writeStream = response.data
          .pipe(fs.createWriteStream(path))
          .on("finish", () => {
            resolve(writeStream);
          });
        }
        else {
          reject(null);
        }
      }).catch((e) => {
        console.log("ERROR");
        console.log(e);
      });
    };
    

    functionName is always "report"

    and reportName is the name of my target template.

    and process.env.JSREPORTURL is either localhost:5488 or the azure function url :https://xxxxxxxxx.azurewebsites.net

    When I am testing this from local to local, it's all working fine, if I pass "executive" as reportName, I get the executive report filled with data, if I pass "single", I get the right report....and so on.

    BUT when I try from my local to my deployed azure function, only the "invoice" report is working when I pass anything else the axios is returning 400

    This is my azure deployed function:

    alt text

    I noticed the the default template after the || operator, so maybe that's why only the 'invoice' is returning a report?

    Am I missing something, should I deploy a separate function for each template/report ? Please help.



  • In case the function is properly deployed, you should be able to render this way all the templates you prepared and have them stored in the data folder.

    jsreport returns 400 when the report rendering fails during the templating engine evaluation for example.
    The 400 error response body should contain some additional information. See how we handle errors in our azure functions starter kit.
    Also, jsreport writes by default to the stdout the logs, you should be able to reach this in the azure function and get more information there as well.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.