Add a web server
This commit is contained in:
parent
3abc3cd68a
commit
bc76506ebc
2 changed files with 45 additions and 2 deletions
29
src/main.rs
29
src/main.rs
|
@ -2,9 +2,13 @@
|
|||
#[macro_use] extern crate diesel_codegen;
|
||||
|
||||
extern crate clap;
|
||||
extern crate hyper;
|
||||
|
||||
use std::net::{SocketAddr, IpAddr};
|
||||
|
||||
mod db;
|
||||
mod schema;
|
||||
mod site;
|
||||
|
||||
fn args<'a>() -> clap::ArgMatches<'a> {
|
||||
use clap::{App, Arg};
|
||||
|
@ -13,15 +17,36 @@ fn args<'a>() -> clap::ArgMatches<'a> {
|
|||
.about("A wiki engine")
|
||||
.arg(Arg::with_name("DATABASE")
|
||||
.help("Sets the database file to use")
|
||||
.required(true)
|
||||
.index(1))
|
||||
.required(true))
|
||||
.arg(Arg::with_name("port")
|
||||
.help("Sets the listening port")
|
||||
.short("p")
|
||||
.long("port")
|
||||
.takes_value(true))
|
||||
.get_matches()
|
||||
}
|
||||
|
||||
fn start_server(bind_host: IpAddr, bind_port: u16) -> Result<(), Box<std::error::Error>> {
|
||||
let server =
|
||||
hyper::server::Http::new()
|
||||
.bind(
|
||||
&SocketAddr::new(bind_host, bind_port),
|
||||
|| Ok(site::Site {})
|
||||
)?;
|
||||
|
||||
server.run()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = args();
|
||||
|
||||
let db_file = args.value_of("DATABASE").expect("Guaranteed by clap");
|
||||
let bind_host = "127.0.0.1".parse().unwrap();
|
||||
let bind_port = args.value_of("port").map(|p| p.parse().expect("Port must be an unsigned integer")).unwrap_or(8080);
|
||||
|
||||
let _db_connection = db::connect_database(db_file, true);
|
||||
|
||||
start_server(bind_host, bind_port).unwrap();
|
||||
}
|
||||
|
|
18
src/site.rs
Normal file
18
src/site.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
extern crate futures;
|
||||
|
||||
use hyper;
|
||||
use hyper::server::*;
|
||||
|
||||
pub struct Site {
|
||||
}
|
||||
|
||||
impl Service for Site {
|
||||
type Request = Request;
|
||||
type Response = Response;
|
||||
type Error = hyper::Error;
|
||||
type Future = futures::BoxFuture<Response, Self::Error>;
|
||||
|
||||
fn call(&self, _req: Request) -> Self::Future {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue