How spawn curl request in function beforeRender ?



  • Hi, how i can do spawn curl request from cmd.exe in function beforeRender ?
    For example

      const { spawn } = require('child_process');
    
       let args = [
           ...some args
        ];
    
        const curl = spawn('curl',
            args, {
                shell: true
            }
        );
    
       curl.on('close', (code) => {
            console.log(`child process exited with code ${code}`);
        });
    
        curl.on('data', (data) => {
            console.log(data)
        });
    

    Thank you in advance



  • Isn't it better to use a nodejs module for making http requests? Like this

    //load some data from the remote API
    function beforeRender(req, res, done) {
        require('request')({
          url:"http://service.url",
          json:true
        }, function(err, res, body){
            req.data = Object.assign({}, req.data, body);
            done();
        });
    }
    


  • i use curl, because i need do request to service, where use kerberos authentication. And i think its possible to do only if use curl with flag --negotiate. Thank you.



  • Maybe I am wrong but I doubt it won't with a module.

    However here is the code for curl you can expand

    const spawn  = require('child_process').spawn
    
    function beforeRender(req, res, done) {
        const curl = spawn('curl', ['https://jsreport.net'], { shell: true })    
    
        curl.stdout.on('data', (data) => {
            console.log(`stdout: ${data}`)
        })
    
        curl.stderr.on('data', (data) => {
            console.error(`stderr: ${data}`)
        })
    
        curl.on('close', (code) => {       
            done()
        })
    }
    


  • Thanks a lot )


Log in to reply
 

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