Browse Source

Do not unwrap on watchers in serve cmd

index-subcmd
Vincent Prouillet 7 years ago
parent
commit
27287a50c3
1 changed files with 11 additions and 7 deletions
  1. +11
    -7
      src/cmd/serve.rs

+ 11
- 7
src/cmd/serve.rs View File

@@ -11,7 +11,7 @@ use staticfile::Static;
use notify::{Watcher, RecursiveMode, watcher}; use notify::{Watcher, RecursiveMode, watcher};
use ws::{WebSocket, Sender}; use ws::{WebSocket, Sender};
use gutenberg::Site; use gutenberg::Site;
use gutenberg::errors::{Result};
use gutenberg::errors::{Result, ResultExt};




use ::{report_elapsed_time, unravel_errors}; use ::{report_elapsed_time, unravel_errors};
@@ -71,6 +71,16 @@ pub fn serve(interface: &str, port: &str, config_file: &str) -> Result<()> {
site.build()?; site.build()?;
report_elapsed_time(start); report_elapsed_time(start);


// Setup watchers
let (tx, rx) = channel();
let mut watcher = watcher(tx, Duration::from_secs(2)).unwrap();
watcher.watch("content/", RecursiveMode::Recursive)
.chain_err(|| format!("Can't watch the `content` folder. Does it exist?"))?;
watcher.watch("static/", RecursiveMode::Recursive)
.chain_err(|| format!("Can't watch the `static` folder. Does it exist?"))?;
watcher.watch("templates/", RecursiveMode::Recursive)
.chain_err(|| format!("Can't watch the `templates` folder. Does it exist?"))?;

let ws_address = format!("{}:{}", interface, "1112"); let ws_address = format!("{}:{}", interface, "1112");


// Start a webserver that serves the `public` directory // Start a webserver that serves the `public` directory
@@ -92,12 +102,6 @@ pub fn serve(interface: &str, port: &str, config_file: &str) -> Result<()> {
ws_server.listen(&*ws_address).unwrap(); ws_server.listen(&*ws_address).unwrap();
}); });


// And finally watching/reacting on file changes
let (tx, rx) = channel();
let mut watcher = watcher(tx, Duration::from_secs(2)).unwrap();
watcher.watch("content/", RecursiveMode::Recursive).unwrap();
watcher.watch("static/", RecursiveMode::Recursive).unwrap();
watcher.watch("templates/", RecursiveMode::Recursive).unwrap();
let pwd = format!("{}", env::current_dir().unwrap().display()); let pwd = format!("{}", env::current_dir().unwrap().display());


println!("Listening for changes in {}/{{content, static, templates}}", pwd); println!("Listening for changes in {}/{{content, static, templates}}", pwd);


Loading…
Cancel
Save