refactor: rename --cors to --enable-cors (#57)
BREAKING CHANGE: `--cors` rename to `--enable-cors`
This commit is contained in:
parent
051ff8da2d
commit
e66951fd11
4 changed files with 16 additions and 17 deletions
|
@ -52,16 +52,15 @@ OPTIONS:
|
||||||
-b, --bind <addr>... Specify bind address
|
-b, --bind <addr>... Specify bind address
|
||||||
-p, --port <port> Specify port to listen on [default: 5000]
|
-p, --port <port> Specify port to listen on [default: 5000]
|
||||||
--path-prefix <path> Specify an url path prefix
|
--path-prefix <path> Specify an url path prefix
|
||||||
-a, --auth <user:pass> Use HTTP authentication
|
-a, --auth <rule>... Add auth for path
|
||||||
--no-auth-access Not required auth when access static files
|
|
||||||
-A, --allow-all Allow all operations
|
-A, --allow-all Allow all operations
|
||||||
--allow-upload Allow upload files/folders
|
--allow-upload Allow upload files/folders
|
||||||
--allow-delete Allow delete files/folders
|
--allow-delete Allow delete files/folders
|
||||||
--allow-symlink Allow symlink to files/folders outside root directory
|
--allow-symlink Allow symlink to files/folders outside root directory
|
||||||
|
--enable-cors Enable CORS, sets `Access-Control-Allow-Origin: *`
|
||||||
--render-index Render index.html when requesting a directory
|
--render-index Render index.html when requesting a directory
|
||||||
--render-try-index Render index.html if it exists when requesting a directory
|
--render-try-index Render index.html if it exists when requesting a directory
|
||||||
--render-spa Render for single-page application
|
--render-spa Render for single-page application
|
||||||
--cors Enable CORS, sets `Access-Control-Allow-Origin: *`
|
|
||||||
--tls-cert <path> Path to an SSL/TLS certificate to serve with HTTPS
|
--tls-cert <path> Path to an SSL/TLS certificate to serve with HTTPS
|
||||||
--tls-key <path> Path to the SSL/TLS certificate's private key
|
--tls-key <path> Path to the SSL/TLS certificate's private key
|
||||||
-h, --help Print help information
|
-h, --help Print help information
|
||||||
|
@ -137,14 +136,14 @@ curl -X DELETE http://127.0.0.1:5000/path-to-file
|
||||||
|
|
||||||
The default render logic is:
|
The default render logic is:
|
||||||
|
|
||||||
- If request for a folder, rendering the folder index listing.
|
- If request for a folder, rendering the directory listing.
|
||||||
- If request for a file, rendering the file.
|
- If request for a file, rendering the file.
|
||||||
- If request target does not exist, returns 404.
|
- If request target does not exist, returns 404.
|
||||||
|
|
||||||
The `--render-*` options change the render logic:
|
The `--render-*` options change the render logic:
|
||||||
|
|
||||||
- `--render-index`: If request for a folder, rendering index.html in the folder. If the index.html file does not exist, return 404.
|
- `--render-index`: If request for a folder, rendering index.html in the folder. If the index.html file does not exist, return 404.
|
||||||
- `--render-try-index`: Like `--render-index`, rendering the folder index listing if the index.html file does not exist, other than return 404.
|
- `--render-try-index`: Like `--render-index`, rendering the directory listing if the index.html file does not exist, other than return 404.
|
||||||
- `--render-spa`: If request target does not exist, rendering `/index.html`
|
- `--render-spa`: If request target does not exist, rendering `/index.html`
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
16
src/args.rs
16
src/args.rs
|
@ -77,6 +77,11 @@ fn app() -> Command<'static> {
|
||||||
.long("allow-symlink")
|
.long("allow-symlink")
|
||||||
.help("Allow symlink to files/folders outside root directory"),
|
.help("Allow symlink to files/folders outside root directory"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("enable-cors")
|
||||||
|
.long("enable-cors")
|
||||||
|
.help("Enable CORS, sets `Access-Control-Allow-Origin: *`"),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("render-index")
|
Arg::new("render-index")
|
||||||
.long("render-index")
|
.long("render-index")
|
||||||
|
@ -92,11 +97,6 @@ fn app() -> Command<'static> {
|
||||||
.long("render-spa")
|
.long("render-spa")
|
||||||
.help("Render for single-page application"),
|
.help("Render for single-page application"),
|
||||||
)
|
)
|
||||||
.arg(
|
|
||||||
Arg::new("cors")
|
|
||||||
.long("cors")
|
|
||||||
.help("Enable CORS, sets `Access-Control-Allow-Origin: *`"),
|
|
||||||
)
|
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("tls-cert")
|
Arg::new("tls-cert")
|
||||||
.long("tls-cert")
|
.long("tls-cert")
|
||||||
|
@ -130,7 +130,7 @@ pub struct Args {
|
||||||
pub render_index: bool,
|
pub render_index: bool,
|
||||||
pub render_spa: bool,
|
pub render_spa: bool,
|
||||||
pub render_try_index: bool,
|
pub render_try_index: bool,
|
||||||
pub cors: bool,
|
pub enable_cors: bool,
|
||||||
pub tls: Option<(Vec<Certificate>, PrivateKey)>,
|
pub tls: Option<(Vec<Certificate>, PrivateKey)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ impl Args {
|
||||||
} else {
|
} else {
|
||||||
format!("/{}/", &path_prefix)
|
format!("/{}/", &path_prefix)
|
||||||
};
|
};
|
||||||
let cors = matches.is_present("cors");
|
let enable_cors = matches.is_present("enable-cors");
|
||||||
let auth: Vec<&str> = matches
|
let auth: Vec<&str> = matches
|
||||||
.values_of("auth")
|
.values_of("auth")
|
||||||
.map(|v| v.collect())
|
.map(|v| v.collect())
|
||||||
|
@ -186,7 +186,7 @@ impl Args {
|
||||||
path_prefix,
|
path_prefix,
|
||||||
uri_prefix,
|
uri_prefix,
|
||||||
auth,
|
auth,
|
||||||
cors,
|
enable_cors,
|
||||||
allow_delete,
|
allow_delete,
|
||||||
allow_upload,
|
allow_upload,
|
||||||
allow_symlink,
|
allow_symlink,
|
||||||
|
|
|
@ -59,7 +59,7 @@ impl Server {
|
||||||
) -> Result<Response, hyper::Error> {
|
) -> Result<Response, hyper::Error> {
|
||||||
let method = req.method().clone();
|
let method = req.method().clone();
|
||||||
let uri = req.uri().clone();
|
let uri = req.uri().clone();
|
||||||
let cors = self.args.cors;
|
let enable_cors = self.args.enable_cors;
|
||||||
|
|
||||||
let mut res = match self.handle(req).await {
|
let mut res = match self.handle(req).await {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
|
@ -77,7 +77,7 @@ impl Server {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if cors {
|
if enable_cors {
|
||||||
add_cors(&mut res);
|
add_cors(&mut res);
|
||||||
}
|
}
|
||||||
Ok(res)
|
Ok(res)
|
||||||
|
|
|
@ -5,7 +5,7 @@ use fixtures::{server, Error, TestServer};
|
||||||
use rstest::rstest;
|
use rstest::rstest;
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn cors(#[with(&["--cors"])] server: TestServer) -> Result<(), Error> {
|
fn cors(#[with(&["--enable-cors"])] server: TestServer) -> Result<(), Error> {
|
||||||
let resp = reqwest::blocking::get(server.url())?;
|
let resp = reqwest::blocking::get(server.url())?;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -21,7 +21,7 @@ fn cors(#[with(&["--cors"])] server: TestServer) -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn cors_options(#[with(&["--cors"])] server: TestServer) -> Result<(), Error> {
|
fn cors_options(#[with(&["--enable-cors"])] server: TestServer) -> Result<(), Error> {
|
||||||
let resp = fetch!(b"OPTIONS", server.url()).send()?;
|
let resp = fetch!(b"OPTIONS", server.url()).send()?;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Reference in a new issue