1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// use hyper::rt::{self, Future};
// use hyper::service::service_fn_ok;
// use hyper::{Body, Request, Response, Server, StatusCode};
fn main() {
// // Create our address to bind to, localhost:3000
// let addr = ([127, 0, 0, 1], 3000).into();
// // Construct our Hyper server.
// let server = Server::bind(&addr)
// .serve(|| {
// use usher::http::HttpRouter;
// use usher::prelude::*;
// // Defines our handler type (just a boxed function).
// type Handler = Box<Fn(Request<Body>) -> Response<Body> + Send + Sync>;
// // Construct our HTTP router using only a static parser.
// let mut router: HttpRouter<Handler> = HttpRouter::new(vec![Box::new(StaticParser)]);
// // Register a handler on the "/" path, for GET requests.
// router.get(
// "/",
// Box::new(|req| {
// let message = format!(
// "Received {} request on path {}",
// req.method(),
// req.uri().path()
// );
// Response::new(message.into())
// }),
// );
// // Create our service function to return a 404.
// service_fn_ok(move |req: Request<Body>| {
// // First we have to extract the method and path combination.
// let method = req.method();
// let path = req.uri().path();
// // Then we look for our handler in the router.
// match router.handler(method, path) {
// // If a handler is found, we just have to call it!
// //
// // In our example we don't care about any captures,
// // but this is where handling for those would also occur.
// Some((handler, _captures)) => handler(req),
// // If no handler matches, keep the 404 response!
// //
// // This acts as a default response to pass back when we
// // can't find a handler to deal with a request.
// None => {
// let mut response = Response::new(Body::empty());
// *response.status_mut() = StatusCode::NOT_FOUND;
// response
// }
// }
// })
// })
// .map_err(|e| eprintln!("server error: {}", e));
// // Log the port we're listening on so we don't forget!
// println!("Listening on http://{}", addr);
// // Initialze the actual service.
// rt::run(server);
}