refactor: rename --cors to --enable-cors (#57)

BREAKING CHANGE: `--cors` rename to `--enable-cors`
This commit is contained in:
sigoden
2022-06-19 17:27:09 +08:00
committed by GitHub
parent 051ff8da2d
commit e66951fd11
4 changed files with 16 additions and 17 deletions

View File

@@ -77,6 +77,11 @@ fn app() -> Command<'static> {
.long("allow-symlink")
.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::new("render-index")
.long("render-index")
@@ -92,11 +97,6 @@ fn app() -> Command<'static> {
.long("render-spa")
.help("Render for single-page application"),
)
.arg(
Arg::new("cors")
.long("cors")
.help("Enable CORS, sets `Access-Control-Allow-Origin: *`"),
)
.arg(
Arg::new("tls-cert")
.long("tls-cert")
@@ -130,7 +130,7 @@ pub struct Args {
pub render_index: bool,
pub render_spa: bool,
pub render_try_index: bool,
pub cors: bool,
pub enable_cors: bool,
pub tls: Option<(Vec<Certificate>, PrivateKey)>,
}
@@ -157,7 +157,7 @@ impl Args {
} else {
format!("/{}/", &path_prefix)
};
let cors = matches.is_present("cors");
let enable_cors = matches.is_present("enable-cors");
let auth: Vec<&str> = matches
.values_of("auth")
.map(|v| v.collect())
@@ -186,7 +186,7 @@ impl Args {
path_prefix,
uri_prefix,
auth,
cors,
enable_cors,
allow_delete,
allow_upload,
allow_symlink,

View File

@@ -59,7 +59,7 @@ impl Server {
) -> Result<Response, hyper::Error> {
let method = req.method().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 {
Ok(res) => {
@@ -77,7 +77,7 @@ impl Server {
}
};
if cors {
if enable_cors {
add_cors(&mut res);
}
Ok(res)