summaryrefslogtreecommitdiff
path: root/src/bin/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/main.rs')
-rw-r--r--src/bin/main.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs
index 245416c..506eba4 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -38,8 +38,8 @@ fn create_admin_user(conn: &rusqlite::Connection) {
}
}
-fn serve(context: systemhttp::server::Context, port: u16) {
- let _server = systemhttp::server::serve(context, port).unwrap();
+fn serve(context: systemhttp::server::Context, state: systemhttp::server::State, port: u16) {
+ let _server = systemhttp::server::serve(context, state, port).unwrap();
println!("Serving on {}", port);
}
@@ -58,6 +58,10 @@ fn main() {
.long("db_file")
.takes_value(true)
.help("Path to sqlite database"))
+ .arg(Arg::with_name("base_url")
+ .long("base_url")
+ .takes_value(true)
+ .help("URL to prepend to links (useful with proxies)"))
.subcommand(SubCommand::with_name("serve")
.about("Start the systemhttpd server"))
.subcommand(SubCommand::with_name("create_admin_user")
@@ -72,19 +76,25 @@ fn main() {
let db_file = matches.value_of("db_file").unwrap();
+ let base_url = matches.value_of("base_url").unwrap_or("").to_string();
+
env_logger::init().unwrap();
let mut conn = rusqlite::Connection::open(db_file)
.expect(format!("opening sqlite database at {}", db_file).as_str());
systemhttp::db::init(&mut conn);
- let mut context = systemhttp::server::Context {
- base_url: "http://localhost:8080".to_string(),
+ let context = systemhttp::server::Context {
+ base_url: base_url,
+ };
+ info!("{:?}", context);
+ let state = systemhttp::server::State {
conn: conn,
};
+ info!("{:?}", state);
match matches.subcommand_name() {
- Some("serve") => serve(context, port),
- Some("create_admin_user") => create_admin_user(&context.conn),
+ Some("serve") => serve(context, state, port),
+ Some("create_admin_user") => create_admin_user(&state.conn),
x => panic!("Don't know about subcommand: {:?}", x),
}
}