summaryrefslogtreecommitdiffstats
path: root/rust/src/bin/fatcat-iron.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-15 00:33:33 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-15 00:33:36 -0700
commit33a4cce0b97832f5f0301b318a0a50073ce6b615 (patch)
tree1b6ba7ec5944d2be2d746510e743a7934f453cd0 /rust/src/bin/fatcat-iron.rs
parent4a1d8f20ab91fda0f4794131144915d0c5214268 (diff)
downloadfatcat-33a4cce0b97832f5f0301b318a0a50073ce6b615.tar.gz
fatcat-33a4cce0b97832f5f0301b318a0a50073ce6b615.zip
revert to v2.3.1 codegen
This reverts back to something compatible with Iron and simple (blocking) parallelism, instead of the new async hyper 0.11 stuff.
Diffstat (limited to 'rust/src/bin/fatcat-iron.rs')
-rw-r--r--rust/src/bin/fatcat-iron.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/rust/src/bin/fatcat-iron.rs b/rust/src/bin/fatcat-iron.rs
new file mode 100644
index 00000000..8c87f55f
--- /dev/null
+++ b/rust/src/bin/fatcat-iron.rs
@@ -0,0 +1,69 @@
+//! Main binary entry point for fatcat implementation.
+
+#![allow(missing_docs)]
+
+// Imports required by this file.
+extern crate fatcat;
+extern crate fatcat_api;
+extern crate swagger;
+extern crate iron;
+//extern crate hyper_openssl;
+extern crate clap;
+
+// Imports required by server library.
+// extern crate fatcat;
+// extern crate swagger;
+extern crate futures;
+extern crate chrono;
+#[macro_use]
+extern crate error_chain;
+
+//use hyper_openssl::OpensslServer;
+//use hyper_openssl::openssl::x509::X509_FILETYPE_PEM;
+//use hyper_openssl::openssl::ssl::{SslAcceptorBuilder, SslMethod};
+//use hyper_openssl::openssl::error::ErrorStack;
+use clap::{App, Arg};
+use iron::{Iron, Chain};
+use swagger::auth::AllowAllMiddleware;
+
+/*
+/// Builds an SSL implementation for Simple HTTPS from some hard-coded file names
+fn ssl() -> Result<OpensslServer, ErrorStack> {
+ let mut ssl = SslAcceptorBuilder::mozilla_intermediate_raw(SslMethod::tls())?;
+
+ // Server authentication
+ ssl.set_private_key_file("examples/server-key.pem", X509_FILETYPE_PEM)?;
+ ssl.set_certificate_chain_file("examples/server-chain.pem")?;
+ ssl.check_private_key()?;
+
+ Ok(OpensslServer::from(ssl.build()))
+}
+*/
+
+/// Create custom server, wire it to the autogenerated router,
+/// and pass it to the web server.
+fn main() {
+ let matches = App::new("server")
+ .arg(Arg::with_name("https")
+ .long("https")
+ .help("Whether to use HTTPS or not"))
+ .get_matches();
+
+ let server = fatcat::server().unwrap();
+ let router = fatcat_api::router(server);
+
+ let mut chain = Chain::new(router);
+ chain.link_before(fatcat_api::server::ExtractAuthData);
+ // add authentication middlewares into the chain here
+ // for the purpose of this example, pretend we have authenticated a user
+ chain.link_before(AllowAllMiddleware::new("cosmo"));
+
+ if matches.is_present("https") {
+ unimplemented!()
+ // Using Simple HTTPS
+ //Iron::new(chain).https("localhost:8080", ssl().expect("Failed to load SSL keys")).expect("Failed to start HTTPS server");
+ } else {
+ // Using HTTP
+ Iron::new(chain).http("localhost:8080").expect("Failed to start HTTP server");
+ }
+}