Make static directory user-configurable. Defaults to /var/lib/webtail-rs/static

Better message printing.

Signed-off-by: Edu4rdSHL <edu4rdshl@protonmail.com>
This commit is contained in:
Edu4rdSHL 2021-06-09 21:28:50 -05:00
parent e1c373cd06
commit b7111ddf62
No known key found for this signature in database
GPG key ID: 3A574A4009F553E5
5 changed files with 42 additions and 29 deletions

View file

@ -14,5 +14,7 @@ pub fn get_args() -> Args {
delay: value_t!(matches.value_of("delay"), u64).unwrap_or(1),
port: value_t!(matches.value_of("port"), u16).unwrap_or(8080),
config_file: value_t!(matches.value_of("config"), String).unwrap_or_default(),
static_folder: value_t!(matches.value_of("static-folder"), String)
.unwrap_or_else(|_| "/var/lib/webtail-rs/static".to_string()),
}
}

View file

@ -1,34 +1,41 @@
name: webtail-rs
author: Eduard Tolosa <edu4rdshl@protonmail.com>
settings:
- ArgRequiredElseHelp
- StrictUtf8
- ArgRequiredElseHelp
- StrictUtf8
about: tail -f for your browser.
args:
- file:
short: f
long: file
help: File to follow.
takes_value: true
multiple: false
- file:
short: f
long: file
help: File to follow.
takes_value: true
multiple: false
- delay:
short: d
long: delay
help: Time between reads.
takes_value: true
multiple: false
- delay:
short: d
long: delay
help: Time between reads.
takes_value: true
multiple: false
- port:
short: p
long: port
help: Port to use.
takes_value: true
multiple: false
- port:
short: p
long: port
help: Port to use.
takes_value: true
multiple: false
- config:
short: c
long: config
help: Config file to use. You can use the path:port syntax for viewing multiple files.
takes_value: true
multiple: false
- config:
short: c
long: config
help: Config file to use. You can use the path:port syntax for viewing multiple files.
takes_value: true
multiple: false
- static-folder:
short: s
long: static-folder
help: Path to the folder which contains the static file 'index.html'.
takes_value: true
multiple: false

View file

@ -37,7 +37,10 @@ fn main() {
.par_iter()
.map(|(file, port)| {
if Path::new(&file).exists() {
println!("\n=> Watching file {} in http://127.0.0.1:{}", file, port);
println!(
"\n=> Watching file \"{}\" in http://127.0.0.1:{}",
file, port
);
let error = rocket::custom(
Config::build(Environment::Production)
.log_level(LoggingLevel::Off)
@ -51,7 +54,7 @@ fn main() {
delay: args.delay,
})
.mount("/", routes![updates])
.mount("/", StaticFiles::from("static"))
.mount("/", StaticFiles::from(args.static_folder.clone()))
.launch();
eprintln!(
"Launch failed for file {} in port {}! Error: {}",

View file

@ -4,6 +4,7 @@ pub struct Args {
pub delay: u64,
pub port: u16,
pub config_file: String,
pub static_folder: String,
}
pub struct File {

View file

@ -29,7 +29,7 @@ impl Read for File {
self.data.clear();
self.data += &format!("data: Watching file {}\ndata: \n", self.name);
self.data += &format!("data: Watching file \"{}\"\ndata: \n", self.name);
for line in utils::return_bufreader(&self.name).lines() {
self.data += &format!("data: {}\n", line.expect("Error"))