MCPcopy Create free account
hub / github.com/YougLin-dev/amp-server / create_router

Method create_router

api/src/proxy/service.rs:28–98  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

26 }
27
28 pub fn create_router(&self) -> Router {
29 let mut router = Router::new();
30
31 for endpoint in self.config.enabled_endpoints() {
32 let endpoint_clone = endpoint.clone();
33 let path = endpoint.path.clone();
34
35 let method = endpoint.method.to_uppercase();
36 let has_wildcard = path.contains("{*");
37
38 match method.as_str() {
39 "GET" => {
40 if has_wildcard {
41 router = router.route(&path, get(move |axum::extract::Path(rest): axum::extract::Path<String>, req| {
42 let mut params = HashMap::new();
43 params.insert("rest".to_string(), rest);
44 Self::handle_proxy_request_with_params(endpoint_clone, params, req)
45 }));
46 } else {
47 router = router.route(&path, get(move |req| {
48 Self::handle_proxy_request(endpoint_clone, req)
49 }));
50 }
51 }
52 "POST" => {
53 if has_wildcard {
54 router = router.route(&path, post(move |axum::extract::Path(rest): axum::extract::Path<String>, req| {
55 let mut params = HashMap::new();
56 params.insert("rest".to_string(), rest);
57 Self::handle_proxy_request_with_params(endpoint_clone, params, req)
58 }));
59 } else {
60 router = router.route(&path, post(move |req| {
61 Self::handle_proxy_request(endpoint_clone, req)
62 }));
63 }
64 }
65 "PUT" => {
66 if has_wildcard {
67 router = router.route(&path, put(move |axum::extract::Path(rest): axum::extract::Path<String>, req| {
68 let mut params = HashMap::new();
69 params.insert("rest".to_string(), rest);
70 Self::handle_proxy_request_with_params(endpoint_clone, params, req)
71 }));
72 } else {
73 router = router.route(&path, put(move |req| {
74 Self::handle_proxy_request(endpoint_clone, req)
75 }));
76 }
77 }
78 "DELETE" => {
79 if has_wildcard {
80 router = router.route(&path, delete(move |axum::extract::Path(rest): axum::extract::Path<String>, req| {
81 let mut params = HashMap::new();
82 params.insert("rest".to_string(), rest);
83 Self::handle_proxy_request_with_params(endpoint_clone, params, req)
84 }));
85 } else {

Callers 1

startFunction · 0.80

Calls 1

enabled_endpointsMethod · 0.80

Tested by

no test coverage detected