cargo-server

Crates.iocargo-server
lib.rscargo-server
version0.3.6
sourcesrc
created_at2022-09-28 19:36:15.748607
updated_at2023-11-12 00:02:47.071644
descriptionHelps you serve a static site, single page application or just a static file
homepage
repositoryhttps://github.com/raphamorim/cargo-server
max_upload_size
id676006
size2,070,124
Raphael Amorim (raphamorim)

documentation

https://github.com/raphamorim/cargo-server#readme

README

cargo-server

tl;dr: Does the same as "python -m http.server" or "npx serve" but for Rust ecosystem and with few more functionalities.

cargo-server helps you serve a static site, single page application or just a static file (no matter if on your device or on the local network). It also provides a neat interface for listing the directory's contents.

You can use cargo to install:

cargo install cargo-server

With cargo-binstall:

cargo binstall cargo-server

Once cargo-server is installed, you can run this command inside your project's directory. It will create by default in 8000 port:

cargo server

--port

To specify the port, you can use --port:

cargo server --port 3000

--open

To open in your browser after run the command just add --open:

cargo server --open

--path

You can also set a custom path using --path:

cargo server --path ./examples/simple-wasm-frontend-app

Result:

Demo

--quiet

Is also possible to run without any stdout using --quiet:

cargo server --quiet --open --path ./examples/simple-wasm-frontend-app

--route

You can create custom routes that returns JSON

--json with params

cargo server \
	--route '/users/:userId' \
	--json '{"data":{"userId":"{!0}","givenName":"Raphael","country":"br"}}' \
	--port 8123

Result:

Demo JSON with params

--json without params

cargo server \
	--route '/users' \
	--json '{"users":[{"data":{"userId":"3","givenName":"Raphael","country":"br"}}]}' \
	--port 8123

Result:

Demo JSON

--all-routes

It will add support for GET, POST, DELETE and PATCH methods as well.

cargo server \
	--all-routes \
	--json '{"id": "1"}' \
	--port 8123

Result:

Demo JSON all routes

--ngnix

In progress...

Commit count: 38

cargo fmt