mirror of
https://github.com/edu4rdshl/webtail-rs.git
synced 2026-07-17 23:24:50 +00:00
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:
parent
e1c373cd06
commit
b7111ddf62
5 changed files with 42 additions and 29 deletions
|
|
@ -14,5 +14,7 @@ pub fn get_args() -> Args {
|
||||||
delay: value_t!(matches.value_of("delay"), u64).unwrap_or(1),
|
delay: value_t!(matches.value_of("delay"), u64).unwrap_or(1),
|
||||||
port: value_t!(matches.value_of("port"), u16).unwrap_or(8080),
|
port: value_t!(matches.value_of("port"), u16).unwrap_or(8080),
|
||||||
config_file: value_t!(matches.value_of("config"), String).unwrap_or_default(),
|
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()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,3 +32,10 @@ args:
|
||||||
help: Config file to use. You can use the path:port syntax for viewing multiple files.
|
help: Config file to use. You can use the path:port syntax for viewing multiple files.
|
||||||
takes_value: true
|
takes_value: true
|
||||||
multiple: false
|
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
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,10 @@ fn main() {
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|(file, port)| {
|
.map(|(file, port)| {
|
||||||
if Path::new(&file).exists() {
|
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(
|
let error = rocket::custom(
|
||||||
Config::build(Environment::Production)
|
Config::build(Environment::Production)
|
||||||
.log_level(LoggingLevel::Off)
|
.log_level(LoggingLevel::Off)
|
||||||
|
|
@ -51,7 +54,7 @@ fn main() {
|
||||||
delay: args.delay,
|
delay: args.delay,
|
||||||
})
|
})
|
||||||
.mount("/", routes![updates])
|
.mount("/", routes![updates])
|
||||||
.mount("/", StaticFiles::from("static"))
|
.mount("/", StaticFiles::from(args.static_folder.clone()))
|
||||||
.launch();
|
.launch();
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"Launch failed for file {} in port {}! Error: {}",
|
"Launch failed for file {} in port {}! Error: {}",
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ pub struct Args {
|
||||||
pub delay: u64,
|
pub delay: u64,
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
pub config_file: String,
|
pub config_file: String,
|
||||||
|
pub static_folder: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct File {
|
pub struct File {
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ impl Read for File {
|
||||||
|
|
||||||
self.data.clear();
|
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() {
|
for line in utils::return_bufreader(&self.name).lines() {
|
||||||
self.data += &format!("data: {}\n", line.expect("Error"))
|
self.data += &format!("data: {}\n", line.expect("Error"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue