17 unstable releases (3 breaking)
|0.3.4||Jun 11, 2021|
|0.3.3||Jun 11, 2021|
|0.3.1||May 31, 2021|
|0.2.2||Apr 23, 2021|
|0.0.8||Dec 16, 2017|
#54 in HTTP server
104 downloads per month
Simple and configurable command-line HTTP server
cargo install http-server
Check for the installation to be successful.
http-server [FLAGS] [OPTIONS] [root-dir]
Flags are provided without any values. For example:
|Cross-Origin Resource Sharing||N/A||
||Enable Cross-Origin Resource Sharing allowing any origin|
||Prints help information|
||Prints version information|
||Prints output to console|
Options receives a value and have support for default values as well.
http-server --host 127.0.0.1
||Address to bind the server||
||Port to bind the server||
||Specifies a configuration file. Example||N/A|
||Enable TLS for HTTPS connections. Requires a Certificate and Key. Reference||N/A|
||Path to TLS certificate file. Depends on
||Path to TLS key file. Depends on
|TLS Key Algorithm||N/A||
||Algorithm used to generate certificate key. Depends on
The following are some relevant details on features supported by this HTTP Server solution that may be of the interest of the user.
When running with TLS support you will need:
- A certificate
- A RSA Private Key for such certificate
A script to generate certificates and keys is available here tls-cert.sh.
This script relies on
openssl, so make sure you have it installed in your system.
http-server as follows:
http-server --tls --tls-cert <PATH TO YOUR CERTIFICATE> --tls-key <PATH TO YOUR KEY> --tls-key-algorithm pkcs8
This HTTP Server brings support to CORS headers out of the box. Based on the headers you want to provide to your HTTP Responses, 2 different methods for CORS configuration are available.
By providing the
--cors option to the
http-server, CORS headers
will be appended to every HTTP Response, allowing any origin.
For more complex configurations, like specifying an origin, a set of allowed HTTP methods and more, you should specify the configuration via the configuration TOML file.
The following example shows all the options available, these options are mapped to the server configuration during initialization.
[cors] allow_credentials = false allow_headers = ["content-type", "authorization", "content-length"] allow_methods = ["GET", "PATCH", "POST", "PUT", "DELETE"] allow_origin = "example.com" expose_headers = ["*", "authorization"] max_age = 600 request_headers = ["x-app-version"] request_method = "GET"
In order to create a release you must push a Git tag as follows
git tag -a <version> -m <message>
git tag -a v0.1.0 -m "First release"
Tags must follow semver conventions Tags must be prefixed with a lowercase
Then push tags as follows:
git push origin main --follow-tags
Every contribution to this project is welcome. Feel free to open a pull request, an issue or just by starting this project.
Distributed under the terms of both the MIT license and the Apache License (Version 2.0)