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

Function main

ch_04/final/src/main.rs:203–257  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

201
202#[tokio::main]
203async fn main() {
204 let store = Store::new();
205 let store_filter = warp::any().map(move || store.clone());
206
207 let cors = warp::cors()
208 .allow_any_origin()
209 .allow_header("content-type")
210 .allow_methods(&[Method::PUT, Method::DELETE, Method::GET, Method::POST]);
211
212 let get_questions = warp::get()
213 .and(warp::path("questions"))
214 .and(warp::path::end())
215 .and(warp::query())
216 .and(store_filter.clone())
217 .and_then(get_questions);
218
219 let update_question = warp::put()
220 .and(warp::path("questions"))
221 .and(warp::path::param::<String>())
222 .and(warp::path::end())
223 .and(store_filter.clone())
224 .and(warp::body::json())
225 .and_then(update_question);
226
227 let delete_question = warp::delete()
228 .and(warp::path("questions"))
229 .and(warp::path::param::<String>())
230 .and(warp::path::end())
231 .and(store_filter.clone())
232 .and_then(delete_question);
233
234 let add_question = warp::post()
235 .and(warp::path("questions"))
236 .and(warp::path::end())
237 .and(store_filter.clone())
238 .and(warp::body::json())
239 .and_then(add_question);
240
241 let add_answer = warp::post()
242 .and(warp::path("comments"))
243 .and(warp::path::end())
244 .and(store_filter.clone())
245 .and(warp::body::form())
246 .and_then(add_answer);
247
248 let routes = get_questions
249 .or(update_question)
250 .or(add_question)
251 .or(add_answer)
252 .or(delete_question)
253 .with(cors)
254 .recover(return_error);
255
256 warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
257}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected