summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2017-07-08 23:51:11 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2017-07-08 23:51:11 -0400
commit24fd328a34b6c9ffef29a8d4566c7d1065ee5682 (patch)
tree734c686561b998eb333291cf5753199d23575b56 /src
Application boilerplate.
Serves an empty page.
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs7
-rw-r--r--src/main.rs29
-rw-r--r--src/server.rs19
3 files changed, 55 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..9ca0a0b
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,7 @@
+#[macro_use]
+extern crate log;
+extern crate iron;
+#[macro_use]
+extern crate router;
+
+pub mod server;
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..2c7905f
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,29 @@
+#[macro_use]
+extern crate log;
+extern crate env_logger;
+extern crate clap;
+extern crate linoquotes_gamma;
+
+use clap::{App, Arg};
+
+fn main() {
+ let matches = App::new("linoquotes")
+ .version("3.0.0")
+ .author("Kjetil Ørbekk")
+ .about("Quote db for #linux.no. Run with \
+ RUST_LOG=linoquotes_gamma=info to enable logging.")
+ .arg(Arg::with_name("port")
+ .short("p").long("port").takes_value(true)
+ .help("Port to serve on"))
+ .get_matches();
+
+ let port = matches
+ .value_of("port")
+ .unwrap_or("8080")
+ .parse::<u16>()
+ .expect("port number");
+
+ env_logger::init().unwrap();
+ info!("Starting");
+ linoquotes_gamma::server::serve(port);
+}
diff --git a/src/server.rs b/src/server.rs
new file mode 100644
index 0000000..3a15e45
--- /dev/null
+++ b/src/server.rs
@@ -0,0 +1,19 @@
+use iron::headers::{ContentType};
+use iron::modifiers::{Header};
+use iron::{Iron, Chain, Request, Response, IronResult, status};
+
+fn info(_r: &mut Request) -> IronResult<Response> {
+ Ok(Response::with((status::Ok,
+ Header(ContentType::html()),
+ "<p>Info")))
+}
+
+pub fn serve(port: u16) {
+ let router = router!(
+ info: get "/" => info,
+ );
+ let chain = Chain::new(router);
+ let bind_address = format!("{}:{}", "::", port);
+ let _server = Iron::new(chain).http(bind_address.as_str());
+ info!("Serving on {}", bind_address);
+}