CORS Problem



  • Hi, i am new to jsReport. Currently i facing one problem:

    const express = require('express');
    const cors = require('cors');
    
    const app = express();
    
    app.use(cors())
    
    const jsreport = require('jsreport')()
    
    if (process.env.JSREPORT_CLI) {
      // export jsreport instance to make it possible to use jsreport-cli
      module.exports = jsreport
    } else {
      jsreport.init().then(() => {
        // running
      }).catch((e) => {
        // error during startup
        console.error(e.stack)
        process.exit(1)
      })
    }
    

    i already enable the CORS, but still received below message :

    message: "Http failure response for https://localhost:5489/api/report: 0 Unknown Error"
    name: "HttpErrorResponse"
    url: "https://localhost:5489/api/report"



  • jsreport has cors enabled by default, maybe you have jsreport running inside another express app or behind a web server that doesn't have cors enabled. Or there is a problem in the client call itself.



  • i have remove all the code i add in.

    but now i have install 'jsreport-browser-client-dist', but don't know how to write :

    import ******** from 'jsreport-browser-client-dist';

    please help !



  • Below is my source code , Angular10 :

    How should i put

    import ******** from 'jsreport-browser-client-dist';

    because if don't put import, jsreport will become 'any'

    grdInvoiceMToolbarPrint() {
        this.jsreport.serverUrl = this.abcSvr.urlReport;
        
        // add custom headers to ajax calls
        //this.jsreport.headers['Authorization'] = 'Basic ' + btoa('admin:password');
    
        const request = {
          'template': { "template": { "name": "invoice" } }
          //'data' : data
        };
         this.jsreport.renderAsync(request).then(function(res) {
           const html = '<html>' +
                   '<style>html,body {padding:0;margin:0;} iframe {width:100%;height:100%;border:0}</style>' +
                   '<body>' +
                   '<iframe type="application/pdf" src="' +  res.toDataURI() + '"></iframe>' +
                   '</body></html>';
           const a = window.open('about:blank', 'Report');
           a.document.write(html);
           a.document.close();
        });
    }
    


  • hi, any part that i have miss out ? ?



  • i know you have be say declare a file 'global.ts' in your project file, perhaps you can tell the 'global.ts' what is inside ?
    preferable the 'global.ts' file.



  • I have no experience with angular, sorry.



  • dear All:

    For those using Angular 7 onward, please help !!!


Log in to reply
 

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