This commit is contained in:
2020-09-26 18:42:41 +02:00
parent 0ff92614c5
commit 92ae649cf6
2 changed files with 19 additions and 21 deletions

View File

@@ -27,12 +27,10 @@ use std::iter::Iterator;
use std::path::Path;
use std::sync::Arc;
use std::sync::Mutex;
use std::net::SocketAddr;
use std::env::{args,self};
#[cfg(not(debug_assertions))]
const STORAGE_DIR: &str = "/snips";
#[cfg(debug_assertions)]
const STORAGE_DIR: &str = "/tmp";
const STORAGE_DIR: &str = "./snips";
lazy_static! {
static ref KNOWN_KEYS: Arc<Mutex<KnownKeys>> = Arc::new(Mutex::new(
@@ -44,7 +42,7 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
fn handle(req: &mut Request) -> IronResult<Response> {
println!("{}", req.url);
let storage = SnippetStorage::new(&Path::new(STORAGE_DIR));
let storage = SnippetStorage::new(&Path::new(&STORAGE_DIR));
let segments: Vec<&str> = req.url.path();
match (&req.method, segments.first()) {
(Method::Get, Some(&"version")) => Ok(Response::with((iron::status::Ok, VERSION))),
@@ -127,5 +125,5 @@ fn handle(req: &mut Request) -> IronResult<Response> {
fn main() {
let chain = Chain::new(handle);
println!("Starting brownpaper: {}", STORAGE_DIR);
Iron::new(chain).http("0.0.0.0:3000").unwrap();
Iron::new(chain).http(args().skip(1).next().map(|ip| ip.parse::<SocketAddr>().expect("can't parse socket address")).unwrap_or("0.0.0.0:3000".parse::<SocketAddr>().unwrap()).to_string().as_str());
}