How to host SPA files and embed files too in executable? #1309
Replies: 3 comments 5 replies
-
I don't have any experience running SPAs using rust-embed so I cannot offer much help. Does rust-embed's axum example help? However |
Beta Was this translation helpful? Give feedback.
-
I opened #1317 for I still don't know how to do the same with |
Beta Was this translation helpful? Give feedback.
-
Hey! I saw this duscussion and thought I'd add how I set up my app. This is ofc not perfect but for a simple demo and for my small usecase it might work out just fine :) I cached the index.html in a HTML using static_init for performance. In case we could not find the file, return the index.html insead.
|
Beta Was this translation helpful? Give feedback.
-
I'm having hard time understanding how to host (and embed) SPA (single page application) files with
rust-embed
andaxum
.To host SPA files with
axum
I'm using a single line of code (from here):It works because all files are correctly downloaded. But:
FIRST PROBLEM
What is missing for a properly SPA handling is the redirect on the
index.html
if for example the user reloads the page on a SPA nested route.Example: I'm on the page:
/home/customers
which is not a file nor a dir but just a fake javascript route and if I reload the page axum gives me404
(Not found).SECOND PROBLEM
I need to embed those files in my final executable. In Golang this is "native" using
embed:
directive.I saw that in Rust this is well done with
rust-embed
but I cannot complete my task for SPA.I opened pyrossh/rust-embed#183 for
rust-embed
side but I think you people can help me understand immediately what the problem is and I can PR another example (very much useful) for future people to come! 😄The need is that every path typed by the user (and that is not an existent file such as
.js
or.css
which obviously must be downloaded by the browser) leads to the "index.html
" file in the root of mystatic
dir.If I use the example axum code I can see the route:
which has
/dist/*file
and I don't need that/dist
because theindex.html
calls many files with custom paths, such as/_works
,menu
,images
.If I remove the
dist
part I get this error:Can you help me understand how to properly accomplish this task?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions