feat: add cors

This commit is contained in:
sigoden
2022-05-29 17:33:21 +08:00
parent 06ce7b0175
commit 10aabcb2f2
5 changed files with 146 additions and 20 deletions

View File

@@ -35,10 +35,10 @@ fn app() -> clap::Command<'static> {
.help("Path to a directory for serving files"),
)
.arg(
Arg::new("no-edit")
.short('E')
.long("no-edit")
.help("Disable editing operations such as update or delete"),
Arg::new("no-change")
.short('C')
.long("no-change")
.help("Disable change operations such as update or delete"),
)
.arg(
Arg::new("auth")
@@ -47,6 +47,11 @@ fn app() -> clap::Command<'static> {
.help("Authenticate with user and pass")
.value_name("user:pass"),
)
.arg(
Arg::new("cors")
.long("cors")
.help("Enable CORS, sets `Access-Control-Allow-Origin: *`"),
)
}
pub fn matches() -> ArgMatches {
@@ -60,6 +65,7 @@ pub struct Args {
pub path: PathBuf,
pub readonly: bool,
pub auth: Option<String>,
pub cors: bool,
}
impl Args {
@@ -72,7 +78,8 @@ impl Args {
let port = matches.value_of_t::<u16>("port")?;
let path = matches.value_of_os("path").unwrap_or_default();
let path = Args::parse_path(path)?;
let readonly = matches.is_present("no-edit");
let readonly = matches.is_present("no-change");
let cors = matches.is_present("cors");
let auth = matches.value_of("auth").map(|v| v.to_owned());
Ok(Args {
@@ -81,6 +88,7 @@ impl Args {
path,
readonly,
auth,
cors,
})
}