Get Error Generating a PDF on Nginx over SSL (DOMException: Failed to read the 'responseText' property from 'XMLHttpRequest')
-
We're evaluating JsReport and getting the error below when trying to generate a PDF using Nginx over SSL. We are able to use the same technique to generate HTML over SSL. Any help would be very much appreciated.
Error Messages
- DOMException: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'arraybuffer').
- Failed to load resource: the server responded with a status of 500 (Internal Server Error) [https://server/report]
Here's the client (browser) code we're using to generate PDFs:
renderAsPdfFile(filename: string) { let deferred = $.Deferred() let request = { template: { content: this.options.html, engine: 'ejs', recipe: 'chrome-pdf' }, data: this.options.data } jsreport.renderAsync(request).then((res) => { res.download(filename) deferred.resolve(true) }).catch((err) => { deferred.reject(false) }) return deferred.promise() }
Here's our nginx.conf based on the JsReport instructions for configuring Nginx
# Based on: https://github.com/jsreport/docs/blob/master/installation/nginx.conf upstream jsreport { server 127.0.0.1:5488; keepalive 15; } server { # Client listen 8080; listen 443 ssl; server_name server_name.com; ssl_certificate /etc/nginx/ssl/is-ssl-com.crt; ssl_certificate_key /etc/nginx/ssl/is-ssl-com.key; location / { root /var/www/client; index index.html index.htm; } #charset koi8-r; # access_log logs/host.access.log main; # API - Reverse proxy. location /api { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } # RPT - Reverse proxy. location /rpt/ { root /var/www/rpt; proxy_pass http://127.0.0.1:5488/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_cache_bypass $http_upgrade; } }
We are able to generate HTML reports using JsReport with this Nginx configuration and using this code on the client:
renderAsHtml(target: string) { let deferred = $.Deferred() let request = { template: { content: this.options.html, engine: 'ejs', recipe: 'html' }, data: this.options.data, options: { debug: true } } jsreport.renderAsync(request) .then((res) => { $('#' + target).empty().append(res.toString()) deferred.resolve(true, res.toString()) }).catch((err, err2) => { deferred.reject(false) }) return deferred.promise() }
-
Also, the code to generate the PDF works on 'localhost' without SSL.
-
Please try to open F12 dev tools / networking and compare response headers and response content
nginx with ssl
nginx no ssl
localhost