Skip to content

Commit f091881

Browse files
committed
chore(cors): document cors feature
1 parent 7e483f7 commit f091881

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
1010
#### Features
1111

12+
* A `Middleware` is implemented bringing the capabilities to act on
13+
`hyper::Request<Body>` before executing the main handler (a.k.a File Explorer)
14+
and to act on the `hyper::Response<Body>` after executing the main handler.
15+
This helps implementing future features which relies on acting on different
16+
stages of the HTTP/S request lifecycle such as logging, authentication, caching
17+
and so on.
18+
1219
* Support for Cross-Origin Resource Sharing
1320

1421
* Using the `--cors` flag when running the HTTP Server will now provide a
@@ -31,11 +38,14 @@ request_method = "GET"
3138
#### Improvements
3239

3340
* Codebase refactor for `server` module, introducing middleware support for
34-
services to programatically build a server instance from the provided `Config`
41+
services to programmatically build a server instance from the provided `Config`
3542

3643
* Replace `full` feature flags on `tokio` and `hyper` with sepecific features,
3744
to reduce crate load on compile time. This improve build times and crate size.
3845

46+
* Improved tests coverage by implementing tests for CLI arguments and config
47+
file parsing
48+
3949
#### Fixes
4050

4151
* Fix issue where the `root_dir` is taken _as is_ from the CLI
@@ -46,6 +56,9 @@ directory for the `FileExplorer`
4656
and uses the current working directory as default `root_dir` as is
4757
done for CLI
4858

59+
* Fix issue where errors returned by any internal service are not
60+
logged to stderr
61+
4962
<a name="v0.2.2"></a>
5063
## v0.2.2 (2021-04-22)
5164

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ http-server --help
4646

4747
Name | Short | Long | Description
4848
--- | --- | --- | ---
49+
Cross-Origin Resource Sharing | N/A | `--cors` | Enable Cross-Origin Resource Sharing allowing any origin
4950
Help | N/A | `--help` | Prints help information
5051
Version | `-V` | `--version` | Prints version information
5152
Verbose | `-v` | `--verbose` | Prints output to console
@@ -73,7 +74,7 @@ TLS Key Algorithm | N/A | `--tls-key-algorithm` | Algorithm used to generate cer
7374
The following are some relevant details on features supported by this HTTP Server
7475
solution that may be of the interest of the user.
7576

76-
### TLS Reference
77+
### TLS (HTTPS)
7778

7879
The TLS solution supported for this HTTP Server is built with [rustls](https://github.com/ctz/rustls)
7980
crate along with [hyper-rustls](https://github.com/ctz/hyper-rustls).
@@ -92,6 +93,34 @@ Run `http-server` as follows:
9293
http-server --tls --tls-cert <PATH TO YOUR CERTIFICATE> --tls-key <PATH TO YOUR KEY> --tls-key-algorithm pkcs8
9394
```
9495

96+
### Cross-Origin Resource Sharing (CORS)
97+
98+
This HTTP Server brings support to CORS headers _out of the box_.
99+
Based on the headers you want to provide to your HTTP Responses, 2
100+
different methods for CORS configuration are available.
101+
102+
By providing the `--cors` option to the `http-server`, CORS headers
103+
will be appended to every HTTP Response, allowing any origin.
104+
105+
For more complex configurations, like specifying an origin, a set of allowed
106+
HTTP methods and more, you should specify the configuration via the configuration
107+
TOML file.
108+
109+
The following example shows all the options available, these options are
110+
mapped to the server configuration during initialization.
111+
112+
```toml
113+
[cors]
114+
allow_credentials = false
115+
allow_headers = ["content-type", "authorization", "content-length"]
116+
allow_methods = ["GET", "PATCH", "POST", "PUT", "DELETE"]
117+
allow_origin = "example.com"
118+
expose_headers = ["*", "authorization"]
119+
max_age = 600
120+
request_headers = ["x-app-version"]
121+
request_method = "GET"
122+
```
123+
95124
## Release
96125

97126
In order to create a release you must push a Git tag as follows

0 commit comments

Comments
 (0)