2018-01-26 03:37:46 +00:00
|
|
|
#![feature(ascii_ctype)]
|
|
|
|
#![feature(conservative_impl_trait)]
|
2018-01-27 10:02:32 +00:00
|
|
|
#![feature(ip_constructors)]
|
2018-01-27 09:47:12 +00:00
|
|
|
#![feature(proc_macro)]
|
2018-01-26 03:37:46 +00:00
|
|
|
|
2018-01-28 08:35:07 +00:00
|
|
|
extern crate base64;
|
2018-02-05 09:23:40 +00:00
|
|
|
#[macro_use] extern crate failure;
|
2018-02-11 02:24:24 +00:00
|
|
|
#[macro_use] extern crate futures;
|
2018-01-26 03:37:46 +00:00
|
|
|
extern crate hyper;
|
|
|
|
extern crate hyper_tls;
|
2018-01-28 22:36:56 +00:00
|
|
|
#[macro_use] extern crate lazy_static;
|
2018-02-12 11:02:54 +00:00
|
|
|
extern crate lru_cache;
|
2018-01-27 09:47:12 +00:00
|
|
|
extern crate maud;
|
2018-02-11 05:17:12 +00:00
|
|
|
extern crate ordermap;
|
2018-02-11 09:53:10 +00:00
|
|
|
extern crate relative_path;
|
2018-01-27 01:01:17 +00:00
|
|
|
extern crate route_recognizer;
|
2018-01-26 12:15:53 +00:00
|
|
|
extern crate semver;
|
2018-01-26 03:37:46 +00:00
|
|
|
#[macro_use] extern crate serde_derive;
|
|
|
|
extern crate serde;
|
|
|
|
extern crate serde_json;
|
|
|
|
#[macro_use] extern crate slog;
|
|
|
|
extern crate slog_json;
|
|
|
|
extern crate tokio_core;
|
|
|
|
extern crate tokio_service;
|
2018-01-26 12:15:53 +00:00
|
|
|
extern crate toml;
|
2018-01-26 03:37:46 +00:00
|
|
|
|
2018-02-05 08:38:04 +00:00
|
|
|
mod utils;
|
2018-01-26 03:37:46 +00:00
|
|
|
mod models;
|
2018-01-26 12:15:53 +00:00
|
|
|
mod parsers;
|
|
|
|
mod interactors;
|
|
|
|
mod engine;
|
2018-01-27 09:47:12 +00:00
|
|
|
mod server;
|
2018-01-26 03:37:46 +00:00
|
|
|
|
2018-01-27 10:02:32 +00:00
|
|
|
use std::env;
|
|
|
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
2018-01-26 03:37:46 +00:00
|
|
|
use std::sync::Mutex;
|
|
|
|
|
|
|
|
use futures::{Future, Stream};
|
|
|
|
use hyper::Client;
|
|
|
|
use hyper::server::Http;
|
|
|
|
use hyper_tls::HttpsConnector;
|
|
|
|
use slog::Drain;
|
|
|
|
use tokio_core::reactor::Core;
|
|
|
|
|
2018-01-27 09:47:12 +00:00
|
|
|
use self::server::Server;
|
2018-01-26 12:15:53 +00:00
|
|
|
use self::engine::Engine;
|
2018-01-26 03:37:46 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let logger = slog::Logger::root(
|
|
|
|
Mutex::new(slog_json::Json::default(std::io::stderr())).map(slog::Fuse),
|
|
|
|
o!("version" => env!("CARGO_PKG_VERSION"))
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut core = Core::new()
|
|
|
|
.expect("failed to create event loop");
|
|
|
|
|
|
|
|
let handle = core.handle();
|
|
|
|
|
|
|
|
let connector = HttpsConnector::new(4, &handle)
|
|
|
|
.expect("failed to create https connector");
|
|
|
|
|
|
|
|
let client = Client::configure()
|
|
|
|
.connector(connector)
|
|
|
|
.build(&core.handle());
|
|
|
|
|
2018-01-27 10:02:32 +00:00
|
|
|
let port = env::var("PORT").unwrap_or_else(|_| "8080".to_string()).parse()
|
|
|
|
.expect("could not read port");
|
|
|
|
|
|
|
|
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::unspecified()), port);
|
2018-01-26 03:37:46 +00:00
|
|
|
|
|
|
|
let http = Http::new();
|
|
|
|
|
2018-02-05 08:38:04 +00:00
|
|
|
let engine = Engine::new(client.clone(), logger.clone());
|
2018-01-26 12:15:53 +00:00
|
|
|
|
2018-02-06 10:09:43 +00:00
|
|
|
let server = Server::new(logger.clone(), engine);
|
2018-01-27 01:01:17 +00:00
|
|
|
|
2018-01-27 09:47:12 +00:00
|
|
|
let serve = http.serve_addr_handle(&addr, &handle, move || Ok(server.clone()))
|
2018-01-27 01:01:17 +00:00
|
|
|
.expect("failed to bind server");
|
2018-01-26 03:37:46 +00:00
|
|
|
|
|
|
|
let serving = serve.for_each(move |conn| {
|
|
|
|
let conn_logger = logger.clone();
|
|
|
|
handle.spawn(conn.then(move |res| {
|
|
|
|
if let Err(err) = res {
|
|
|
|
info!(conn_logger, "server connection error: {}", err)
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}));
|
|
|
|
Ok(())
|
|
|
|
});
|
|
|
|
|
2018-01-27 10:02:32 +00:00
|
|
|
println!("Server running on port {}", port);
|
|
|
|
|
2018-01-26 03:37:46 +00:00
|
|
|
core.run(serving).expect("server failed");
|
|
|
|
}
|