use tokio::{self, io, net::TcpListener};

use router::{Method, Request, Response, Router};

mod router;

const ADDR: &str = "127.0.0.1:8080";

#[tokio::main]
async fn main() -> io::Result<()> {
    let listener = TcpListener::bind(ADDR).await?;
    let router = Router::default().route(Method::Get, "/", home);

    router.serve(listener).await;

    Ok(())
}

async fn home(_req: Request) -> Response {
    let html = "
        <!DOCTYPE html>
        <html>
            <head>
                <title>Example</title>
            </head>
            <body>
                <h1>Hello</h1>
            </body>
        </html>    
    ";

    Response::new_html(html)
}
