summaryrefslogtreecommitdiffstats
path: root/rust/src/bin/fatcatd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/bin/fatcatd.rs')
-rw-r--r--rust/src/bin/fatcatd.rs40
1 files changed, 23 insertions, 17 deletions
diff --git a/rust/src/bin/fatcatd.rs b/rust/src/bin/fatcatd.rs
index 682f5038..34652105 100644
--- a/rust/src/bin/fatcatd.rs
+++ b/rust/src/bin/fatcatd.rs
@@ -1,29 +1,35 @@
#![allow(missing_docs)]
-extern crate chrono;
-extern crate clap;
-extern crate diesel;
-//extern crate dotenv;
-extern crate error_chain;
-extern crate fatcat;
-extern crate fatcat_api_spec;
-extern crate futures;
-extern crate iron;
-extern crate iron_slog;
#[macro_use]
extern crate slog;
-extern crate slog_async;
-extern crate slog_term;
+#[macro_use]
+extern crate hyper;
use clap::{App, Arg};
+use fatcat::errors::*;
+use fatcat::server::*;
+use iron::middleware::AfterMiddleware;
use iron::modifiers::RedirectRaw;
use iron::{status, Chain, Iron, IronResult, Request, Response};
use iron_slog::{DefaultLogFormatter, LoggerMiddleware};
use slog::{Drain, Logger};
+// HTTP header middleware
+header! { (XClacksOverhead, "X-Clacks-Overhead") => [String] }
+
+pub struct XClacksOverheadMiddleware;
+
+impl AfterMiddleware for XClacksOverheadMiddleware {
+ fn after(&self, _req: &mut Request, mut res: Response) -> iron::IronResult<Response> {
+ res.headers
+ .set(XClacksOverhead("GNU aaronsw, jpb".to_owned()));
+ Ok(res)
+ }
+}
+
/// Create custom server, wire it to the autogenerated router,
/// and pass it to the web server.
-fn main() {
+fn main() -> Result<()> {
let matches = App::new("server")
.arg(
Arg::with_name("https")
@@ -38,7 +44,7 @@ fn main() {
let logger = Logger::root(drain, o!());
let formatter = DefaultLogFormatter;
- let server = fatcat::server().unwrap();
+ let server = create_server()?;
info!(
logger,
"using primary auth key: {}", server.auth_confectionary.identifier,
@@ -59,7 +65,6 @@ fn main() {
router.get("/v0/openapi2.yml", yaml_handler, "openapi2-spec-yaml");
fn root_handler(_: &mut Request) -> IronResult<Response> {
- //Ok(Response::with((status::Found, Redirect(Url::parse("/swagger-ui").unwrap()))))
Ok(Response::with((
status::Found,
RedirectRaw("/swagger-ui".to_string()),
@@ -92,7 +97,7 @@ fn main() {
chain.link_before(fatcat_api_spec::server::ExtractAuthData);
chain.link_before(fatcat::auth::MacaroonAuthMiddleware::new());
- chain.link_after(fatcat::XClacksOverheadMiddleware);
+ chain.link_after(XClacksOverheadMiddleware);
if matches.is_present("https") {
unimplemented!()
@@ -100,6 +105,7 @@ fn main() {
// Using HTTP
Iron::new(chain)
.http(host_port)
- .expect("Failed to start HTTP server");
+ .expect("failed to start HTTP server");
}
+ Ok(())
}