stephanrauh / ngx-extended-pdf-viewer

A full-blown PDF viewer for Angular 16, 17, and beyond
https://pdfviewer.net
Apache License 2.0
450 stars 168 forks source link

Locale.json getting from same domain when setting assetsFolder #2259

Closed YaromichSergey closed 2 months ago

YaromichSergey commented 3 months ago

Trying to use library files from different domain to cache it. pdfDefaultOptions.assetsFolder setting to static.domain.com for example but locale(locale.json) files requested from current(mydomain.com/assets/locale/locale.json). Is it possible to also ask locale from assetsFolder? It's bug?

stephanrauh commented 3 months ago

I've set pdfDefaultOptions.assetsFolder = 'http://127.0.0.1:4200/assets' and now it loads the pdf.js resource files from "127.0.0.1" (instead of using "localhost"). So I don't think there's a bug. What does your configuration look like?

YaromichSergey commented 3 months ago

All resource files loaded from assetsFolder except of locale. We have something like https://{dynamicname}.domain.com. All resources we want to take from https://static.domain.com. We faced with issue with cache so we decided to make own version for assets. And full assetsFolder looks like 'https://static.domain.com/assets/version19_5' and in angular.json move files to assets/version19_5.Files 'mjs' works fine, but assets(also locally) trying to request from /assets/locale. We expect /assets/version19_5/locale.

YaromichSergey commented 2 months ago

Hi, any other news about this?

stephanrauh commented 2 months ago

I'm afraid I don't have any news. I don't know how to reproduce your issue. And it's hard to solve an issue I can't see. Maybe you can help me with an idea how to reproduce it?

YaromichSergey commented 2 months ago

Steps to reproduce:

  1. After installing files, in angular.json { "glob": "*/", "input": "node_modules/ngx-extended-pdf-viewer/assets/", "output": "/assets/pdfview3/" },
  2. In component, which using ngx-extended-pdf-viewer, in ngOnInit(can be something else) pdfDefaultOptions.assetsFolder = 'https://static.' + environment.mainDomain + '/assets/pdfview3'; And when we trying to use like this, javascript files works as expected, but locale trying to fetch from http://localhost:4200/assets/locale/locale.json (expecting http://localhost:4200/assets/pdfview3/locale/locale.json).

Looks like assets/locale hardcoded and not related to assetsFolder variable.

YaromichSergey commented 2 months ago

assetsFolder it's sample how we want to use it. In localhost, i try to emulate to show you, what I'm expecting. Hope you undestand idea and it might be enough.

stephanrauh commented 2 months ago

I've followed your steps and ended up with https://github.com/stephanrauh/ngx-extended-pdf-viewer-issues/tree/main/issue2259. It works flawlessly. Can you clone or download my reproducer and check whether it works on your machine, too? That should enable you to hunt down the difference between your project and my project.

image
YaromichSergey commented 2 months ago

That works fine on your project. But when I'm trying to use on own, still have image

Could you make your changes to branch and we try to use them? Or mb you have any other ideas? using in angular.json image using inside component image

Am I missing something?

stephanrauh commented 2 months ago

I don't have a clue. You can set [minifiedJSLibraries]="false" and debug the source code to find out where the locale path is set. It's probably in the viewer-*.mjs file:


  static async #getPaths() {
    try {
      const { href } = document.querySelector(`link[type="application/l10n"]`);
      const paths = await fetchData(href, /* type = */ "json");

      return { baseURL: href.replace(/[^/]*$/, "") || "./", paths };
    } catch {}
    return { baseURL: "./", paths: Object.create(null) };
  }
``´
stephanrauh commented 2 months ago

Did you make any progress? I don't want to let you down, but I really don't have a clue how to help you.

You've mentioned it works in my project, and I assume that means you've cloned my project and it works on your machine, too. So it's almost certainly not a problem of my library. Hence, I'm closing the ticket now.

That's doesn't mean I'll stop supporting you. Feel free to add comments to the tickets, and I'll read and answer them. I still hope we'll figure it out together!

Best regards, Stephan