Premium support for our pure JavaScript UI components


Post by mmelcot »

Hi,

I have a question which is a bit in the grayzone between bryntum and nginx, so I am not sure if this forum is the right place.

We have a setup, where our app using Bryntum Scheduler, and the PDF Exporter, are in 2 separate Docker containers.
Both are proxied by a Nginx server

The application is served behind https://my_domain/ (proxying https://localhost:8000, the app)
The pdf-exporter is served behind https://my_domain/pdf-exporter (proxying https://localhost:9080, the pdf exporter)

location /pdf-exporter/ {
    proxy_pass https://localhost:9080/;
}

location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header Host $http_host;
    proxy_pass https://localhost:8000/;
}

When the browser requests a pdf, the pdf exporter runs correctly (as I saw it in its log), but the returned URL is incorrect, as it points to 'https://localhost:9080/my_file.pdf' (pdf exporter URL after nginx), rather than 'https://my_domain/pdf-exporter/my_file.pdf'

In the PDF exporter I can find that the pdf file URL is built like the following:

url     : me.setFile(req.protocol + '://' + req.get('host') + req.originalUrl, request, file)

However it is unclear to me which headers can/should be passed by Nginx, or if this snippet should be tweaked, to make the pdf exporter answers a correct url.

Thanks in advance for your help


Post by Maxim Gorkovsky »

Hello and welcome to the grey zone.
I can see few options here:

  1. Try to use private parameter to make PDF server to return binary, instead of link, smth like:
    new Grid({
      features : {
        pdfExport : {
          openAfterExport : false,
          fetchOptions : { sendAsBinary : true }
        }
      },
      listeners : {
        export({ response }) {
          // response should contain PDF file itself, use File API to save it
        }
    })
  2. Adjust nginx to not only proxy requests, but also transform them as they pass through, replacing string https://localhost:9080 to correct one using regular expression.
  3. Replace URL on the client side:
    new Grid({
      features : {
        pdfExport : {
          openAfterExport : false
        }
      },
      listeners : {
        export({ response }) {
          // response would contain JSON with URL `https://localhost:9080`, replace it with correct one and download file via URL.
          // keep in mind file only lives for ~10 seconds
        }
    })

Post by mmelcot »

Hi Maxim, ok thanks for these 3 ideas.

I implemented the option 3 and that did the job! Thanks!


Post Reply