summaryrefslogtreecommitdiffstats
path: root/rust/src/bin/fatcatd.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-23 18:05:28 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-24 15:21:32 -0700
commiteb8bedb469f837c8943bd07b008117850ef60e48 (patch)
treecd12c9133c2f2bcb4963a90ee90d12512faff708 /rust/src/bin/fatcatd.rs
parent4ffd65c7ed400a5762f8b5e25f23f6815685c6d8 (diff)
downloadfatcat-eb8bedb469f837c8943bd07b008117850ef60e48.tar.gz
fatcat-eb8bedb469f837c8943bd07b008117850ef60e48.zip
serve up swagger UI
Diffstat (limited to 'rust/src/bin/fatcatd.rs')
-rw-r--r--rust/src/bin/fatcatd.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/rust/src/bin/fatcatd.rs b/rust/src/bin/fatcatd.rs
index f33c3763..19357c9e 100644
--- a/rust/src/bin/fatcatd.rs
+++ b/rust/src/bin/fatcatd.rs
@@ -17,7 +17,7 @@ extern crate slog_async;
extern crate slog_term;
use clap::{App, Arg};
-use iron::{Chain, Iron};
+use iron::{Chain, Iron, IronResult, Response, Request, status};
use iron_slog::{DefaultLogFormatter, LoggerMiddleware};
use slog::{Drain, Logger};
//use dotenv::dotenv;
@@ -42,7 +42,18 @@ fn main() {
let formatter = DefaultLogFormatter;
let server = fatcat::server().unwrap();
- let router = fatcat_api::router(server);
+ let mut router = fatcat_api::router(server);
+
+ router.get("/swagger-ui", swaggerui_handler, "swagger-ui-html");
+ router.get("/v0/openapi2.yml", yaml_handler, "openapi2-spec-yaml");
+
+ fn swaggerui_handler(_: &mut Request) -> IronResult<Response> {
+ let html_type = "text/html".parse::<iron::mime::Mime>().unwrap();
+ Ok(Response::with((html_type, status::Ok, include_str!("../../swagger-ui/index.html"))))
+ }
+ fn yaml_handler(_: &mut Request) -> IronResult<Response> {
+ Ok(Response::with((status::Ok, include_str!("../../fatcat-openapi2.yml"))))
+ }
let mut chain = Chain::new(LoggerMiddleware::new(router, logger, formatter));