Hacker News new | ask | show | jobs
by chinedufn 2880 days ago
Sure!

The backend is pretty much this (messy) file - https://github.com/chinedufn/percy/blob/master/examples/isom... .

It

1. Pulls in your application crate 2. Initializes your app (more or less sets initial state 3. Renders your app's virtual DOM into an HTML string 4. Serves the HTML to the client, along with the initial state serialized into JSON in a script tag (using serde-json) 5.Also serves the WASM script and the JS that initializes the WASM

So that's your server crate. Then your client crate also pulls in your same application crate and you compile it to WebAssembly and that's what runs browser side.

Feel free to let me know if any of that was poorly explained!

1 comments

Thanks, that makes sense. I haven't built web servers with Rust as yet; so it was a bit difficult to follow the code.
This is good enough for an example, but for a "real" web server, you wouldn't do this; you'd use a framework that handles a lot of this kind of thing for you. I think this code was adapted from the final chapter of the Rust book, which is mostly about learning how to write a simple thing than being production-ready.