Embed frontend/dist in application #1255
Closed
jakobsack
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Hey @jakobsack, Dotan and I discussed this feature a lot when we started the project. We explored ways to hide the overhead configuration from the user and make it work without any additional setup—ideally, just through a feature flag. Could you open an issue for adding this feature? We’ll explore the best way to implement it—and of course, you’re welcome to join us! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there,
I'm writing a small application with Loco 0.14 backend and React frontend. So far the experience was pleasantly smooth and reminded me a lot of my Rails days 👍
However, on your homepage you claim that only the binary and a config folder is needed to deploy the app. In my experience this does not work, the
frontend/dist
needs to be next to be in the CWD. But what if I could embed the assets in the build? Well, turns out that this is easily doable. All it needs are those three commandsThen set the edit
src/controllers/frontend.rs
:Disable serving of static assets in the config, start the app, and it just works.
A lot of the code is inspired by the rust-embed axum SPA example.
I'm pretty sure that it's possible to improve the code, maybe it even is possible to make this a middleware with a proper check if
npm run build
has been executed before. But so far I am happy with the solution and will go with it until something better ships with Loco or I'll use nginx again to serve the assets (more performant, but more files to copy).Take care!
Disclaimer: This code works but for sure is not the best possible implementation. Also, I do not consider myself an experienced Rust developer.
Beta Was this translation helpful? Give feedback.
All reactions