404 on Newly Created Assets

50 views
Skip to first unread message

Dale Lehman

unread,
Sep 10, 2019, 12:11:13 AM9/10/19
to Angular and AngularJS discussion
I'm building an Angular 8 application that collects user input and generates PDF files from it. I'm storing the generated files in a directory outside the web root and using a symlink to access them for display on the web page using ng2-pdf-viewer, e.g.:

<pdf-viewer [src]="http://localhost:4200/assets/pdfs/my_report.pdf"></pdf_viewer>

In this URL, "pdfs" is the symlink to the folder where "my_report.pdf" was created. However, the file isn't found. If I copy/paste the above URL into the browser's location bar, the router treats it as a 404. The odd thing is, if I stop ng and restart it, then the URL works as expected. It appears that Angular is caching the state of the assets directory at start-up and not recognizing any new files added to it. I've spent a couple of hours searching for an explanation of this and the right way to handle such situations but came up empty. Does anyone here know if assets is cached or indexed on startup, and if so is there a way to force it to reload/reindex it when new files are added? If not, where is the proper place to store files created on the fly and how does one tell the router where to find them? Thank you.


Sander Elias

unread,
Sep 10, 2019, 3:45:42 AM9/10/19
to Angular and AngularJS discussion
Hi Dale,

ng serve is a development tool and not a server. Because of that it is optimized for speed and doesn't monitor the assets folder. As you correctly assessed, it does cache on startup.
The proper place for such files is hosting them on a secondary service(nginx would be a good fit). Then put in a proxy config, so everything that goes to `/staticAssets` (or any name you like) if forwarded to the secondary service. 

With kind regards
Sander

Dale Lehman

unread,
Sep 10, 2019, 9:03:04 AM9/10/19
to Angular and AngularJS discussion
Hi Sander,

Thank you. I'll look into that.

--Dale

Dale Lehman

unread,
Sep 10, 2019, 10:01:31 AM9/10/19
to Angular and AngularJS discussion
Quick followup: I already had a NodeJS service for handling database queries, so I just added an endpoint to it to fetch the PDF by name, and that worked like a charm. Thanks again!

--Dale

Reply all
Reply to author
Forward
0 new messages