How to return custom header in jsreport response?



  • Is there any way to return the custom header while returning the report file in the response?

    We need this as a common thing like middleware.



  • You can use res.meta.headers in the jsreport scripts

    function afterRender(req,res) {
      res.meta.headers['MY-HEADER'] = 'xxx'
    }
    
    


  • Is there any way we can do this in serer.js?

    We want to send this info in every response. While sending the response we want to use some information received in the incoming API request and after doing some processing, we will send the custom header in the response.



  • You can set headers in the express middleware the same way as express documents. Using res.setHeader

    Or you can add afterRender listener to jsreport

     jsreport.init().then(() => {
        jsreport.afterRenderListeners.add('mylistener', (req,res) => {
          console.log('here')
          res.meta.headers['MY-HEADER'] = 'xxx'
        })
        // running
      })
    

    Or you can implement global jsreport script that will do it for every report.


Log in to reply
 

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