summaryrefslogtreecommitdiffstats
path: root/rust/src/bin/fatcatd.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-01-08 23:18:32 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-01-08 23:20:53 -0800
commitba7d6a842cb4d61357b588fb2d3ec552c654ae64 (patch)
tree41eb8c465cd1ad0a9f70e18f49905adf7e5c3b40 /rust/src/bin/fatcatd.rs
parenteb6fb8e5fe1efb3fbb927d13075cf5a1b33aa83e (diff)
downloadfatcat-ba7d6a842cb4d61357b588fb2d3ec552c654ae64.tar.gz
fatcat-ba7d6a842cb4d61357b588fb2d3ec552c654ae64.zip
huge refactor of rust modules/files
Taking advantage of new Rust 2018 crate/module path changes, and re-organizing things. Somewhat optimistic this could help with partial rebuild speed also.
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(())
}