aboutsummaryrefslogtreecommitdiffstats
path: root/rust/fatcat-api/examples/server.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-09-11 13:59:32 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-09-11 13:59:32 -0700
commitcd8e09fcb6ee0a1b23c0bd57d0f097f99fd6d828 (patch)
treefbd5c91c576a2fce2c44cfe36e5754b69aedc046 /rust/fatcat-api/examples/server.rs
parent0dc872921023030f6ffd320eb038e5379b47fa53 (diff)
downloadfatcat-cd8e09fcb6ee0a1b23c0bd57d0f097f99fd6d828.tar.gz
fatcat-cd8e09fcb6ee0a1b23c0bd57d0f097f99fd6d828.zip
refactor fatcat-api => fatcat-api-spec
Diffstat (limited to 'rust/fatcat-api/examples/server.rs')
-rw-r--r--rust/fatcat-api/examples/server.rs64
1 files changed, 0 insertions, 64 deletions
diff --git a/rust/fatcat-api/examples/server.rs b/rust/fatcat-api/examples/server.rs
deleted file mode 100644
index 8d2e9b64..00000000
--- a/rust/fatcat-api/examples/server.rs
+++ /dev/null
@@ -1,64 +0,0 @@
-//! Main binary entry point for fatcat implementation.
-
-#![allow(missing_docs)]
-
-// Imports required by this file.
-// extern crate <name of this crate>;
-extern crate clap;
-extern crate fatcat;
-extern crate hyper_openssl;
-extern crate iron;
-extern crate swagger;
-
-// Imports required by server library.
-// extern crate fatcat;
-// extern crate swagger;
-extern crate chrono;
-extern crate futures;
-#[macro_use]
-extern crate error_chain;
-
-use clap::{App, Arg};
-use hyper_openssl::openssl::error::ErrorStack;
-use hyper_openssl::openssl::ssl::{SslAcceptorBuilder, SslMethod};
-use hyper_openssl::openssl::x509::X509_FILETYPE_PEM;
-use hyper_openssl::OpensslServer;
-use iron::{Chain, Iron};
-use swagger::auth::AllowAllMiddleware;
-
-mod server_lib;
-
-/// 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 = server_lib::server().unwrap();
- let router = fatcat::router(server);
-
- let mut chain = Chain::new(router);
- chain.link_before(fatcat::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") {
- // 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");
- }
-}