extern crate hyper;
extern crate iron;
extern crate mount;
extern crate percent_encoding;
extern crate router;
mod not_shared;
mod receive;
mod serve_file;
mod serve_html;
use iron::error::HttpError;
use iron::method::Method;
use iron::Iron;
use router::Router;
use serve_html::ServeHtml;
use std::net::SocketAddr;
use std::path::PathBuf;
pub fn start(
port: u16,
receive: bool,
send_file: &Option<PathBuf>,
) -> Result<iron::Listening, HttpError> {
let mut router = Router::new();
router.route(
Method::Get,
"*",
not_shared::not_shared_handler,
"not_shared_files",
);
if receive {
router.route(
Method::Put,
"/*",
receive::upload_receive_handler,
"upload_put",
);
}
if let Some(path) = &send_file {
let serve_file = serve_file::ServeFile::new(path.to_path_buf());
router.route(Method::Get, "*", serve_file, "file");
}
let serve_html = ServeHtml::new(&send_file, receive);
router.route(Method::Get, "/", serve_html, "index");
let addr = SocketAddr::from(([0, 0, 0, 0], port));
Iron::new(router).http(addr)
}