brson / basic-http-server Goto Github PK
View Code? Open in Web Editor NEWA simple static HTTP server in Rust, for learning and local doc development
A simple static HTTP server in Rust, for learning and local doc development
Example page: https://github.com/rust-lang/rustup.rs#working-with-nightly-rust
Anchors don't work in basic-http-server. Naming is wrong.
At the moment it seems that on every request, a file is loaded from disk. Can this be cached?
This URL results in 404: "http://localhost:4001/blog/2019-07-28%20Call%20for%20Contributors"
I'm using a wasm compiled version of Stockfish for a chess game I'm working on and it requires SharedArrayBuffer which requires these headers to be sent in order to use it:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
I assume there are or will be other features gated by headers like this and it would be very useful to be able to easily test these on local machines. Would you be interested in a PR to support setting these headers?
For implementation, I was thinking just a command line argument like --header/-h that can be specified multiple times and takes a string like "Cross-Origin-Opener-Policy: same-origin". I'd also be fine with something like a --sharedarraybuffer flag if that's preferred, I just figured setting headers might be useful for other use cases. Would appreciate input on any of this.
Is there any guide how to host this in production?
It's annoying to have to get full paths correct to load up files.
Preface: this is fabulous, and I really appreciate that the code is a good source as well as this having great functionality.
Feature request: it'd be great if this supported serving wasm
with the correct MIME type!
# RUST_BACKTRACE=1 rnn ~rust/.multirust/toolchains/nightly/cargo/bin/basic-http-server -a '127.0.0.1:80'
addr: 127.0.0.1:80
root dir: "."
server threads: 4
file threads: 100
listening on 127.0.0.1:80
listening on 127.0.0.1:80
listening on 127.0.0.1:80
listening on 127.0.0.1:80
thread '<unnamed>' panicked at 'Called write_body() method on message in a state IgnoredBody', .multirust/toolchains/nightly/cargo/registry/src/github.com-48ad6e4054423464/rotor-http-0.6.0/src/message.rs:368
stack backtrace:
1: 0x566ea59c - std::sys::backtrace::tracing::imp::write::h9fb600083204ae7f
2: 0x566edbd1 - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hca543c34f11229ac
3: 0x566ed811 - std::panicking::default_hook::hc2c969e7453d080c
4: 0x566de731 - std::sys_common::unwind::begin_unwind_inner::h30e12d15ce2b2e25
5: 0x566df6f7 - std::sys_common::unwind::begin_unwind_fmt::hb2de8a9968d38523
6: 0x5668c64e - rotor_http::message::Message::write_body::hb9825fc1585197ed
7: 0x5668c3bb - rotor_http::server::response::Response::write_body::hd82d8f206e8c2fb7
8: 0x5667f76a - _<RequestState as rotor_http..server..Server>::wakeup::hd4c2460d23f61854
9: 0x5667a1c8 - rotor::handler::machine_loop::h0bbf68048047d20a
10: 0x5665f749 - basic_http_server::run_server::hd44294626e68af33
11: 0x56658e89 - std::sys_common::unwind::try::try_fn::h7a084651e7e45c71
12: 0x566e96b7 - __rust_try
13: 0x566e9636 - std::sys_common::unwind::inner_try::h47a4d9cd4a369dcd
14: 0x5665afab - _<F as std..boxed..FnBox<A>>::call_box::h942bb108389dc8b5
15: 0x566ec349 - std::sys::thread::Thread::new::thread_start::h6f266e069bf4ec2b
16: 0xf7714d96 - start_thread
17: 0xf765374d - clone
18: 0x0 - <unknown>
^C
The server continues to work, but after 3 more such errors it hangs.
(these two are actix-web based, http-server-rs has been updated recently to latest)
Compiling basic-http-server v0.2.0
Finished release [optimized] target(s) in 170.55 secs
Replacing /home/rust/.cargo/bin/basic-http-server
$ /home/rust/.cargo/bin/basic-http-server --version
basic-http-server 0.1
Some other small(-ish) dev servers like live-server support watching served files and automatically reloading any connected browsers.
This is super handy for development! It could also serve as a good example for how add WebSockets into a Rust project, something that can be finnicky in web frameworks that don't account for it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.