Inject a base url for my remote api that is called by a number of scripts in the jsreport online service



  • Hello,

    I am able to set a root url via the dotenv package for my on premise reporting service, but I couldn't find in the documentation how do accomplish the same thing using the online reporting service.

    Here's an example from my on premise server:

    const process = require('process');
    var getRequest = require('request');
    
    function beforeRender(req, res, done) {
        var baseUrl = process.env.JSREPORT_BASE_URL;
    
        var url = baseUrl + 'balance_due_listing/';
        console.log(url + req.data.campaignId);
    
        getRequest(url + req.data.campaignId, function(err, resp, body) {
            console.log(body);
            if (err) {
                return done(err);
            }
    
            req.data.rows = JSON.parse(body);
              console.log(req.data.rows);      
    
            done();
        }) 
    

    I'm not set on a specific method of doing this, I would just like to be able to update the baseUrl depending on my environment.

    Thanks!



  • I see you are looking for a centralized place where to put your configurations.
    You can use assets for this.
    https://jsreport.net/learn/assets

    For example approach like here
    https://playground.jsreport.net/w/anon/e_BQ6Ggc



  • Thanks, the key here for me was creating the script as an asset (config.js), not a Script.


Log in to reply
 

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