D
D
Drovosek012021-11-03 23:46:16
Angular
Drovosek01, 2021-11-03 23:46:16

How to determine in Angular whether this is a locally built project or a project that is open on production?

Good day.

There is the following situation:
The project uses the Angular PDF Viewer - https://github.com/VadimDez/ng2-pdf-viewer
For its operation, the following construction is used, as in the documentation example:

(<any>window).pdfWorkerSrc = 'assets/scripts/pdf.worker.min.js';


Problem:
On the locally assembled front, everything works fine.
This does not work on the assembled and launched on the production front, because this project on the server is opened not from the domain root (i.e. not from mysite.org), but somewhat deeper (i.e. from mysite.org/some-path /another-path/). Accordingly, with the above js construction, the application tries to get this PDF Worker from the root, i.e. from mysite.org/assets/scripts/pdf.worker.min.js, but you need from mysite.org/some-path/another-path/assets/scripts/pdf.worker.min.js
If I change the line in the code above assets/scripts/pdf.worker.min.json the
some-path/another-path/assets/scripts/pdf.worker.min.js
, then this will stop working on the locally assembled front.

Accordingly, as I understand it, in order to solve this problem, I need to know when the front is going locally and when it is being built. How to find out from the component code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2021-11-04
@KickeRockK

You can check the environment variables .
But I would explicitly tell him which link to use. From environment'a take -apiUrl

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question