diff --git a/Cargo.toml b/Cargo.toml index 40604f3..d73341c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "urouter" -version = "0.3.4" +version = "0.3.5" edition = "2021" license = "MIT" repository = "https://github.com/ivabus/urouter" diff --git a/src/main.rs b/src/main.rs index a897e97..7601ae7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,6 +47,10 @@ struct Args { #[arg(long, default_value = "./alias.json")] alias_file: PathBuf, + /// For internal usage + #[arg(long, default_value = "false")] + alias_file_is_set_not_a_list: bool, + /// Dir to lookup file alias #[arg(long, default_value = ".")] dir: PathBuf, @@ -58,6 +62,12 @@ struct Args { port: u16, } +// For better compatability with Nix (with set on the top of alias.json instead of a list) +#[derive(Deserialize, Clone, Debug)] +struct NixJson { + alias: Vec, +} + #[derive(Deserialize, Clone, Debug)] struct Alias { uri: String, @@ -136,12 +146,15 @@ async fn index(user_agent: UserAgent) -> Response { #[rocket::main] async fn main() -> Result<(), rocket::Error> { let args = Args::parse(); + let alias: Vec = if args.alias_file_is_set_not_a_list { + let set: NixJson = + serde_json::from_str(&smurf::io::read_file_str(&args.alias_file).unwrap()).unwrap(); + set.alias + } else { + serde_json::from_str(&smurf::io::read_file_str(&args.alias_file).unwrap()).unwrap() + }; unsafe { - ALIAS - .set( - serde_json::from_str(&smurf::io::read_file_str(&args.alias_file).unwrap()).unwrap(), - ) - .unwrap(); + ALIAS.set(alias).unwrap(); } let figment = Figment::from(rocket::Config::default())