Persisting Vite static assets a service
scarabcoder
PROOP

2 years ago

In order to prevent new releases from causing users on-page to encounter page crashes (due to code-split resources no longer being available), I'm trying to persist the build artifacts from Vite after each build.

I use Caddy right now to serve the static Vite build (built with Nixpacks), and it's working great. However, when I attach a volume to /app/frontend/dist (my build location, frontend is a subdirectory of the monorepo), and re-deploy, I get a 404 for all requests made. The volume has data on it, and I can see that it's at 1GB (which seems excessive, the build should be < 20mb).

I'm unable to actually look at the volume and investigate, but I can't see any reason why this wouldn't be working.

Solved

10 Replies


2 years ago

volumes are not available during build, the assets are placed in dist during build, and then during runtime the volume is mounted there, the volume being empty means dist is now empty.

you would need to run the build during runtime, or more preferably (imo), use a cdn for assets.


scarabcoder
PROOP

2 years ago

Hm, thanks. A CDN is a little tricky because we proxy requests through Railway to serve on the same origin, which helps make PR environment deployments work.


2 years ago

something that serves the assets externally (either externally from railway or externally from the railway service) is best since services with a volume will have downtime between deploys


scarabcoder
PROOP

2 years ago

Got it. We currently use CloudFlare pages to do this, but the big downside is that means we can't make it available in PR environments. Is there some way to pass the URL generated from a Github action to a Railway PR environment?


2 years ago

we don't have any way to natively inject variables into pr envs


scarabcoder
PROOP

2 years ago

Gotcha, so it wouldn't be possible to serve a static application CDN and be able to use Railway PR environments?


2 years ago

i mean its all about implementation, im sure theres some way to do it, its just i havent done it myself


maddsua
HOBBY

2 years ago

Personally I would just use a proper CI that supports caching and artifacts to do the builds


2 years ago

!s


Status changed to Solved brody over 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...