Coder Social home page Coder Social logo

raphamorim / cargo-server Goto Github PK

View Code? Open in Web Editor NEW
26.0 3.0 0.0 852 KB

serve a static site, single page application or just a static file with Rust

Home Page: https://crates.io/crates/cargo-server

License: Mozilla Public License 2.0

Makefile 13.00% Rust 87.00%
file-server rust-lang server simple-server static-site

cargo-server's Introduction

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...

cargo-server's People

Contributors

raphamorim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.