Serving static assets (like images) from public/?

I know Glitch ‘wants’ us to store static assets (like images) in the assets ‘folder’. But can they be put into public/ as well, and served from there too?

Although I understand the setup in Glitch, the assets ‘folder’ has a separate endpoint in https://cdn.glitch.com, and the application is retrieving images from there. The assets folder will not be part of the export / download though. So, if I want to host my project from a server ‘outside’ Glitch, I manually need to get the assets and put those in a separate location in the application.

I tried to just create (upload) PNG files in the public/ folder, like suggested in http://expressjs.com/en/starter/static-files.html, but it seems that those files aren’t served correctly from that location?

You can serve items in the assets folder from a relative path, like /public, by using assets.lib. However, it sounds like you want to store assets in /public too, which is trickier. Serving using Express static files should work, so it’s not clear what the problem is. How did you upload them? Manually dragging/dropping will add them to assets, you’d have to import via GitHub or wget etc via the console to get assets into that location. They’ll be hidden from the file tree, but will exist in your project.

2 Likes

Ha, this solves my requirement as well - didn’t know this. Thanks.

Sorry to necromancer this thread but I just ran into this same issue and worked around it by importing from GitHub. @Gareth I was wondering why the images directory is hidden from the file tree?

Binary files are hidden from the filetree as they can’t be viewed in the editor.