Use jsreport without running it as a server



  • Hi

    I wonder if jsreport can used without running it as a server.

    In my case I have a backend (nest.js) with some api’s used by my frontend (quasar.js). My backend, when running locally on my machine, everything works just fine, using the jsreport package and initializing jsreport like this:

      static async init(port: number) {
        this._jsReporter = new jsreport.Reporter({
          httpPort: port,
          httpsPort: null, 
          authentication: {
            enabled: false
          }
        })
    
        this._jsReporter.init().then(() => {
          console.log('\x1b[32mReporter\x1b[0m is listening on port', this._port)
          this._ready = true
        })
      } 
    

    and render reports like this:

    if (this._ready) return this._jsReporter.render( { template: { … } } ) // Returns a PDF file
    else { ... }
    

    But when I deploy to Azure (as a Web App), my backend fails when calling jsReport.init(), with errors related to the port I use, it seems.

    I wonder, if jsReport can be used without having it running as a Server, but e.g. just as function like this:

    import * as jsreport from 'jsreport'
    
    const options = { ... }
    return jsreport.render( { template: { … } }, options ) // Returns a PDF file
    

    Where no port in options are needed. That would be super simple (and cool).

    Thanks for any advise.



  • The express extension is the one that starts the web server and you just need to disable it. To speed things up you can disable the studio or other extensions you don't need as well.

    const jsreport = require('jsreport')({
        extensions: {
            express: { enabled: false },
            studio: { enabled: false }
        }
    })
    await jsreport.init()
    

    Updated docs:
    https://jsreport.net/learn/adapting-jsreport#running-without-web-server



  • Thank you! I can confirm it works perfectly! 💪

    When I test it, after my solution is deployed to Azure, it returns this error:

    spawn UNKNOWNat ChildProcess.spawn (node:internal/child_process:413:11)at Object.spawn (node:child_process:700:9)at BrowserRunner.start (C:\home\site\wwwroot\node_modules\puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:119:34)at ChromeLauncher.launch (C:\home\site\wwwroot\node_modules\puppeteer\lib\cjs\puppeteer\node\ChromeLauncher.js:76:16)at async createBrowser (C:\home\site\wwwroot\node_modules\@jsreport\jsreport-chrome-pdf\lib\chromePoolStrategy.js:98:26)at async allocateBrowser (C:\home\site\wwwroot\node_modules\@jsreport\jsreport-chrome-pdf\lib\chromePoolStrategy.js:113:5)at async getBrowser (C:\home\site\wwwroot\node_modules\@jsreport\jsreport-chrome-pdf\lib\chromePoolStrategy.js:23:30)at async module.exports (C:\home\site\wwwroot\node_modules\@jsreport\jsreport-chrome-pdf\lib\conversion.js:11:19)at async execute (C:\home\site\wwwroot\node_modules\@jsreport\jsreport-chrome-pdf\lib\chromePoolStrategy.js:20:22)at async C:\home\site\wwwroot\node_modules\@jsreport\jsreport-chrome-pdf\lib\lazyRecipe.js:61:20 {errno: -4094,code: 'UNKNOWN',syscall: 'spawn',logged: true,previousOperationId: 'bdjcmdtyp5aaqey'}
    

    Any idea of what goes wrong?





  • Chrome didn't run on the plain windows azure web apps the last time I checked.

    I'm afraid you need to use the Linux-based web app in azure or docker-based web app.


Log in to reply
 

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