Skip to content

Add an embedded web server in own workspace #1007

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

Conversation

pnkfelix
Copy link
Member

Revisiting #982 by putting the new static site serving code into its own Cargo workspace, to avoid increasing build time for the usual blog authors.

Also took @Mark-Simulacrum 's advice from #982 (comment) and added a message at the end of the default running binary to remind the user about ways they might get their hands a preview of the generated web site.

(I did explore tiny_http as suggested by @bjorn3 in #982 (comment) , but it took me a lot more code to get a static site up and running, and I wasn't as confident that my prototype would behave well against "unexpected" urls it received)

pnkfelix added 7 commits July 19, 2022 10:21
(I'm not yet trying to do any fancy monitoring of changes to the files and
subsequent regeneration. This is all meant to be very bare bones.)

To accomplish this I had to make the main crate callable from other crates,
which in turn required some small changes to how it pulls in its own child
modules, since `main` can no longer assume it is the crate root.
… blog generation.

(trying to make change history here clearer by renaming `main.rs`.)
@Mark-Simulacrum
Copy link
Member

Just for my own understanding, is there a reason printing the right python command isn't enough for your use case? It seems ok to do this regardless, ultimately, but I would appreciate the insight.

@pnkfelix
Copy link
Member Author

Just for my own understanding, is there a reason printing the right python command isn't enough for your use case? It seems ok to do this regardless, ultimately, but I would appreciate the insight.

The cargo run -p serve command I'm providing here integrates both the blog generation and the file service. (In my ideal world, it would be generalized to regenerate the html pages as the markdown source is updated; this is admittedly at best a baby step towards such a goal.)

I freely admit that one can get the same composition of actions via cargo run && python3 -m http.server --directory {ROOT}/site. So really, this is more my trying to snapshot some work while still thinking about how best to push it further forward in the future.

@Mark-Simulacrum
Copy link
Member

Hm, sure. I think even with the watch functionality we'd plausibly be just generating the files on disk and letting the webserver (python or something fancier which might auto refresh browser) handle that part of the puzzle.

I'll give it a review code wise for now and merge if it seems good.

@Mark-Simulacrum Mark-Simulacrum merged commit 25091bc into rust-lang:master Jul 20, 2022
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 this pull request may close these issues.

2 participants