mirror of
https://github.com/agersant/polaris
synced 2024-12-11 05:42:56 +00:00
Serve /web files from app data rather than relative path.
Also added CLI option to serve from custom path.
This commit is contained in:
parent
f6ca5bace4
commit
6084ad2703
1 changed files with 19 additions and 7 deletions
26
src/main.rs
26
src/main.rs
|
@ -77,14 +77,15 @@ fn run() -> Result<()> {
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
let mut options = Options::new();
|
let mut options = Options::new();
|
||||||
options.optopt("c", "config", "set the configuration file", "FILE");
|
options.optopt("c", "config", "set the configuration file", "FILE");
|
||||||
|
options.optopt("w", "web", "set the path to web client files", "DIRECTORY");
|
||||||
let matches = match options.parse(&args[1..]) {
|
let matches = match options.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => panic!(f.to_string()),
|
Err(f) => panic!(f.to_string()),
|
||||||
};
|
};
|
||||||
let config_file_name = matches.opt_str("c");
|
|
||||||
let config_file_path = config_file_name.map(|n| Path::new(n.as_str()).to_path_buf());
|
|
||||||
|
|
||||||
// Parse config
|
// Parse config
|
||||||
|
let config_file_name = matches.opt_str("c");
|
||||||
|
let config_file_path = config_file_name.map(|n| Path::new(n.as_str()).to_path_buf());
|
||||||
let config = config::Config::parse(config_file_path)?;
|
let config = config::Config::parse(config_file_path)?;
|
||||||
|
|
||||||
// Init VFS
|
// Init VFS
|
||||||
|
@ -96,8 +97,9 @@ fn run() -> Result<()> {
|
||||||
let index_ref = index.clone();
|
let index_ref = index.clone();
|
||||||
std::thread::spawn(move || index_ref.run());
|
std::thread::spawn(move || index_ref.run());
|
||||||
|
|
||||||
// Start server
|
// Mount API
|
||||||
println!("Starting up server");
|
println!("Mounting API");
|
||||||
|
let mut mount = Mount::new();
|
||||||
let mut api_chain;
|
let mut api_chain;
|
||||||
{
|
{
|
||||||
let api_handler;
|
let api_handler;
|
||||||
|
@ -113,10 +115,20 @@ fn run() -> Result<()> {
|
||||||
let cookie_middleware = oven::new(auth_secret.into_bytes());
|
let cookie_middleware = oven::new(auth_secret.into_bytes());
|
||||||
api_chain.link(cookie_middleware);
|
api_chain.link(cookie_middleware);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut mount = Mount::new();
|
|
||||||
mount.mount("/api/", api_chain);
|
mount.mount("/api/", api_chain);
|
||||||
mount.mount("/", Static::new(Path::new("web")));
|
|
||||||
|
// Mount static files
|
||||||
|
println!("Mounting static files");
|
||||||
|
let web_dir_name = matches.opt_str("w");
|
||||||
|
let mut default_web_dir = utils::get_data_root()?;
|
||||||
|
default_web_dir.push("web");
|
||||||
|
let web_dir_path = web_dir_name
|
||||||
|
.map(|n| Path::new(n.as_str()).to_path_buf())
|
||||||
|
.unwrap_or(default_web_dir);
|
||||||
|
|
||||||
|
mount.mount("/", Static::new(web_dir_path));
|
||||||
|
|
||||||
|
println!("Starting up server");
|
||||||
let mut server = Iron::new(mount).http(("0.0.0.0", 5050))?;
|
let mut server = Iron::new(mount).http(("0.0.0.0", 5050))?;
|
||||||
|
|
||||||
// Start DDNS updates
|
// Start DDNS updates
|
||||||
|
|
Loading…
Reference in a new issue