A simple static HTTP server in Rust.
basic-http-server is designed for two purposes:
as a teaching tool. It is a simple and well-commented example of basic
tokio,hyper, and asynchronous Rust programming, withasync/await.for local development. It serves static HTML content, and with the
-xflag, provides convenience features useful for creating developer documentation, including markdown rendering and directory listing.
The entire reference source for setting up a hyper HTTP server is contained in main.rs. The ext.rs file contains developer extensions.
Developer extensions
When passed the -x flag, basic-http-server enables additional conveniences useful for developing documentation locally. Those extensions are:
Rendering files with the ".md" extension as Markdown.
Listing directories when no "index.html" file is found.
Serving common source code files as "text/plain" so they are rendered in the browser.
This makes basic-http-server useful for the following scenarios:
Previewing markdown content. Draft your
README.mdchanges and view them locally before pushing to GitHub.Navigating to local documentation, including Rust API documentation. Just run
basic-http-server -xin your project directory, and use the directory listing to navigate totarget/doc, then find the crates to read from there (cargo docdoesn't put anindex.htmlfile intarget/doc).
Installation and Use
Note that basic-http-server is not production-ready and should not be exposed to the internet. It is a learning and development tool.
Install with cargo install:
$ cargo install basic-http-server
$ basic-http-serverTo turn on the developer extensions, pass -x:
$ basic-http-server -xTo increase logging verbosity use RUST_LOG:
RUST_LOG=basic_http_server=trace basic-http-server -xCommand line arguments:
USAGE:
basic-http-server [FLAGS] [OPTIONS] [ARGS]
FLAGS:
-x Enable developer extensions
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-a, --addr <ADDR> Sets the IP:PORT combination (default "127.0.0.1:4000")
ARGS:
ROOT Sets the root directory (default ".")from https://github.com/brson/basic-http-server-----我的补充说明:登录linux vps,安装rust环境,然后,
git clone https://github.com/brson/basic-http-server basic-http-server-by-brson
cd basic-http-server-by-brson
cargo build --release
然后在当前目录的子目录target/release/下,会生成可执行文件basic-http-server。
然后cd到某个目录,比如家目录~,运行:
~/basic-http-server-by-brson/target/release/basic-http-server -x --addr 0.0.0.0:2345
然后在你本地机器的浏览器里访问http://vps-public-ip:2345 ,浏览器里即可显示你的vps的~目录的内容。
--------
类似的项目:
https://github.com/gdamjan/http-server-rs
https://github.com/svenstaro/miniserve
https://github.com/iamwwc/rust-webserver
No comments:
Post a Comment