MCPcopy Index your code
hub / github.com/Rust-Web-Development/code / main

Function main

ch_08/src/main.rs:13–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11
12#[tokio::main]
13async fn main() {
14 let log_filter = std::env::var("RUST_LOG").unwrap_or_else(|_| {
15 "handle_errors=warn,practical_rust_book=warn,warp=warn".to_owned()
16 });
17
18 let store =
19 store::Store::new("postgres://localhost:5432/rustwebdev").await;
20
21 sqlx::migrate!()
22 .run(&store.clone().connection)
23 .await
24 .expect("Cannot run migrations");
25
26 let store_filter = warp::any().map(move || store.clone());
27
28 tracing_subscriber::fmt()
29 // Use the filter we built above to determine which traces to record.
30 .with_env_filter(log_filter)
31 // Record an event when each span closes. This can be used to time our
32 // routes' durations!
33 .with_span_events(FmtSpan::CLOSE)
34 .init();
35
36 let cors = warp::cors()
37 .allow_any_origin()
38 .allow_header("content-type")
39 .allow_methods(&[
40 Method::PUT,
41 Method::DELETE,
42 Method::GET,
43 Method::POST,
44 ]);
45
46 let get_questions = warp::get()
47 .and(warp::path("questions"))
48 .and(warp::path::end())
49 .and(warp::query())
50 .and(store_filter.clone())
51 .and_then(routes::question::get_questions);
52
53 let update_question = warp::put()
54 .and(warp::path("questions"))
55 .and(warp::path::param::<i32>())
56 .and(warp::path::end())
57 .and(store_filter.clone())
58 .and(warp::body::json())
59 .and_then(routes::question::update_question);
60
61 let delete_question = warp::delete()
62 .and(warp::path("questions"))
63 .and(warp::path::param::<i32>())
64 .and(warp::path::end())
65 .and(store_filter.clone())
66 .and_then(routes::question::delete_question);
67
68 let add_question = warp::post()
69 .and(warp::path("questions"))
70 .and(warp::path::end())

Callers

nothing calls this directly

Calls 1

initMethod · 0.45

Tested by

no test coverage detected