An option in the middle is webview[0] which will "appify" it by using OS-native browser lib so you don't have to carry Chromium, V8, or all the multi-process ugliness but you still get the web stack.
Also everybody, don't forget to check your Host headers when building apps running HTTP daemons locally or you'll be open to DNS rebinding attack. And if your use case can support it, a random port is nice too.
0 - https://github.com/zserge/webview 1 - https://en.wikipedia.org/wiki/DNS_rebinding
What? This is nothing like Electron. What it's like is shipping the `node` executable to the end-user along with a .js script. The whole point of Electron is that it bundles a browser.
Ah, that's a good explanation as to why zserge/webview recommends serving using ephemeral ports.
Also, wanted to pull in from the readme: webview supports interacting with the javascript environment directly, so a web server isn't strictly required.
Why should a desktop app even care about host headers?
Glad I'm not the only one.
When I was younger, I made a hobby Linux distro that ran completely on floppies with a custom filesystem hierarchy. All the binaries were in /Programs and were statically linked against uClibc. Even X was statically linked, there was some abandoned branch of XFree86 that ran with a VESA driver and fit under 1.44 MB. I thought that I was the bee's knees.
All this was still possible ~2007. Not sure how masochistic you'd have to be to try today.
If you're interested in stuff like this for go, I've used https://github.com/GeertJohan/go.rice with great success.
[EDIT]
"feature" -> "side effect"
"rust and golang" -> "rust and golang being able to produce static binaries"
For example, you can do the import with gcc this way: https://balau82.wordpress.com/2012/02/19/linking-a-binary-bl...
With Green Hills, there is a .rawimport directive.
Apple and Microsoft systems have been supporting this on their native toolchains since the mid-90's.
Thanks to this short blog post by OP I learned something that will let me simplify some of my code.
However the thing that I am doing is not completely useless, because I have been able to embed fonts, favicon and images as well with the method that I am using.
The code I have written for this is only the beginning but if anyone wants to look at my code in order to see how I did it here you go:
https://gist.github.com/ctsrc/4c4cc05254d12bbc8937a0ea385fcd...
It's far from great but it's a start. Let me know how you would do it better :)
Speaking of Rust and websites, in Python I have fallen in love with the pyTenjin templating engine. http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html. Does anyone know of a templating engine like pyTenjin but for Rust?
FWIW there's also an include_bytes! macro to embed binary data right into the executable without going through a separate rustification step.
But, AFAIK, only supports Pure Perl code, so one is SOL for most database drivers etc...
0 - http://github.com/astraw/bui-backend 1 - https://github.com/DenisKolodin/yew
If the single binary that just serves static files you're better off with a web server that supports https, rules, vhosts, etc and is battle tested. Not to mention that this binary you created will need startup scripts of some sort depending on the platform.
I'm pretty sure the use case of this is more akin to an electron replacement, and not a production web server. So the user would just download and run the binary, and interact with the app from their browser.
Strange how some people are obsessed with hype. I think what raised interest of this article was just word "Rust" in the title. Rust seems to be wet dream of many developers. They heard it's safe, so it will magically solve all their problems. But the usage of Rust in this case is meaningless. You could do the same with python, nodejs, java, just plain nginx or million other (and better) ways. Just first google query returned probably better solution if you like single static binary http://miniweb.sourceforge.net/. It would be two files instead of one miniweb binary and static site compressed as 7z.
How does this thing scale? What about SSL? Do I have to put reverse SSL terminating proxy in front of it? Yes, you say? Ok, why not just use that proxy for serving those static files too (nginx does that) and skip this thing completely. What about performance? Have you tried to httperf on it?
I would appreciate if this did more then just being a single binary. Like Facebook's HipHop compiler of PHP to static executable or something like that. Sorry but this is real bullshit.
Know any good nginx books or courses?
I'm betting that almost every language that I've used has something like this, but the succinctness of it and how it's used to keep the source clean, but still compile in the text is really cool.
With a little bit of effort it's also possible to build and statically link native modules, eg I've had success with nodegit, uws and sqlite. (Needed to rebuild some of the node deps with musl, then rebuilding the native modules with musl, then modifying Node's node.gyp to --whole-archive include the additional .a/.o's (done in nexe), and using rollup to rewrite the .node includes to `process._linkedBinding('the registered module name')`, and then nexe builds the whole lot into a single executable.)
Nexe supports bundling resources (although less cleanly than `include_str` imo) so it can also bundle all your ui resources as well.
Its a bit short though. I would really like to see the setup of a simple uni- or even bi-directional rpc or value binding mechanism between react and rust.
There's just a small typo. The script path in the HTML mount file and the router path need to be the same, but do not match. Either one needs to change:
// ui/dist/index.html
<script src="/main.js"></script>
// src/main.rs
(GET) ["/bundle.js"] => {
Response::text(bundle)
},I'm wondering if people who prefer Phython prefer Rust? I've been developing for 20+ years and the syntax alone makes Rust feel prohibitive to me.