mirror of
https://github.com/ivabus/urouter
synced 2024-11-24 09:25:10 +03:00
0.3.4: add dir option to specify dir to lookup files
Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
parent
9122166285
commit
1f3896bb76
2 changed files with 9 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "urouter"
|
||||
version = "0.3.3"
|
||||
version = "0.3.4"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
repository = "https://github.com/ivabus/urouter"
|
||||
|
|
|
@ -47,6 +47,10 @@ struct Args {
|
|||
#[arg(long, default_value = "./alias.json")]
|
||||
alias_file: PathBuf,
|
||||
|
||||
/// Dir to lookup file alias
|
||||
#[arg(long, default_value = ".")]
|
||||
dir: PathBuf,
|
||||
|
||||
#[arg(short, long, default_value = "127.0.0.1")]
|
||||
address: IpAddr,
|
||||
|
||||
|
@ -87,10 +91,13 @@ impl<'r> FromRequest<'r> for UserAgent {
|
|||
}
|
||||
|
||||
fn get_return(alias: &Alias) -> Response {
|
||||
let args = Args::parse();
|
||||
let mut dir = args.dir.clone();
|
||||
return match alias.is_url {
|
||||
Some(true) => Response::Redirect(Redirect::to(alias.alias.clone())),
|
||||
_ => {
|
||||
Response::Text(RawText(smurf::io::read_file_str(&PathBuf::from(&alias.alias)).unwrap()))
|
||||
dir.push(&PathBuf::from(&alias.alias));
|
||||
Response::Text(RawText(smurf::io::read_file_str(&dir).unwrap()))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue