Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example of deployment with http server/files #53

Closed
soundprojects opened this issue Mar 31, 2019 · 2 comments · Fixed by #68
Closed

example of deployment with http server/files #53

soundprojects opened this issue Mar 31, 2019 · 2 comments · Fixed by #68

Comments

@soundprojects
Copy link

Hi,

great library! I am currently creating the front end in Vue JS. Now I am in development and I point the webview to localhost when the Vue JS dev server is on.

But now.. on to production. In the readme it says that local resources only work when using a http server to serve the files. However: how does one embed the files with a rust binary?

And if that is not possible, how can I use include_str! so that I don't get the "Local resource cannot be loaded" errors

Thanks

@green-s
Copy link
Contributor

green-s commented Apr 1, 2019

You could use rust-embed (or includedir or include_dir), or tar/zip your files in your build script and embed with include_bytes!, then traverse/unpack at runtime.

Then you set up the routing of your web server (e.g. actix-web) to resolve to the embedded files. If using rust-embed you call get(path) on the generated struct. You could use mime_guess to set the content type.

It's probably only worth doing this for release builds since include_* macros can significantly increase compile times. AFAIK that's a compiler bug that may be fixed but for now I'm not sure there's much you can do apart from appending the files to the binary somehow.

@passy
Copy link
Contributor

passy commented Apr 2, 2019

Depending on how many resources you have, you may be able to get away with just inlining them manually. In my case I could just use base64 data URIs and include_str! the HTML file. But if you require a build step for your JS, @green-s's option sounds great.

richardhozak added a commit that referenced this issue Sep 25, 2019
richardhozak added a commit that referenced this issue Sep 25, 2019
richardhozak added a commit that referenced this issue Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants