MCPcopy Create free account
hub / github.com/Rust-Web-Development/code / main

Function main

ch_05/src/main.rs:11–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9
10#[tokio::main]
11async fn main() {
12 let store = store::Store::new();
13 let store_filter = warp::any().map(move || store.clone());
14
15 let cors = warp::cors()
16 .allow_any_origin()
17 .allow_header("content-type")
18 .allow_methods(&[Method::PUT, Method::DELETE, Method::GET, Method::POST]);
19
20 let get_questions = warp::get()
21 .and(warp::path("questions"))
22 .and(warp::path::end())
23 .and(warp::query())
24 .and(store_filter.clone())
25 .and_then(routes::question::get_questions);
26
27 let update_question = warp::put()
28 .and(warp::path("questions"))
29 .and(warp::path::param::<String>())
30 .and(warp::path::end())
31 .and(store_filter.clone())
32 .and(warp::body::json())
33 .and_then(routes::question::update_question);
34
35 let delete_question = warp::delete()
36 .and(warp::path("questions"))
37 .and(warp::path::param::<String>())
38 .and(warp::path::end())
39 .and(store_filter.clone())
40 .and_then(routes::question::delete_question);
41
42 let add_question = warp::post()
43 .and(warp::path("questions"))
44 .and(warp::path::end())
45 .and(store_filter.clone())
46 .and(warp::body::json())
47 .and_then(routes::question::add_question);
48
49 let add_answer = warp::post()
50 .and(warp::path("comments"))
51 .and(warp::path::end())
52 .and(store_filter.clone())
53 .and(warp::body::form())
54 .and_then(routes::answer::add_answer);
55
56 let routes = get_questions
57 .or(update_question)
58 .or(add_question)
59 .or(add_answer)
60 .or(delete_question)
61 .with(cors)
62 .recover(return_error);
63
64 warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
65}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected