|
1 | 1 | use base::{ |
2 | | - extract_flow_setting_field, |
3 | 2 | runner::{ServerContext, ServerRunner}, |
4 | 3 | store::FlowIdentifyResult, |
5 | 4 | traits::{IdentifiableFlow, LoadConfig, Server as ServerTrait}, |
@@ -36,12 +35,26 @@ struct RequestRoute { |
36 | 35 |
|
37 | 36 | impl IdentifiableFlow for RequestRoute { |
38 | 37 | fn identify(&self, flow: &ValidationFlow) -> bool { |
39 | | - let url = extract_flow_setting_field(&flow.settings, "HTTP_URL", "url"); |
40 | | - let regex_str = match url.as_deref() { |
41 | | - Some(s) => s, |
42 | | - None => return false, |
| 38 | + let regex_str = flow |
| 39 | + .settings |
| 40 | + .iter() |
| 41 | + .find(|s| s.flow_setting_id == "HTTP_URL") |
| 42 | + .and_then(|s| s.value.as_ref()) |
| 43 | + .and_then(|v| v.kind.as_ref()) |
| 44 | + .and_then(|k| match k { |
| 45 | + Kind::StringValue(s) => Some(s.as_str()), |
| 46 | + _ => None, |
| 47 | + }); |
| 48 | + |
| 49 | + let Some(regex_str) = regex_str else { |
| 50 | + return false; |
43 | 51 | }; |
44 | 52 |
|
| 53 | + print!( |
| 54 | + "Comparing regex {} with literal route: {}", |
| 55 | + regex_str, self.url |
| 56 | + ); |
| 57 | + |
45 | 58 | match regex::Regex::new(regex_str) { |
46 | 59 | Ok(regex) => regex.is_match(&self.url), |
47 | 60 | Err(err) => { |
@@ -71,19 +84,32 @@ impl ServerTrait<HttpServerConfig> for HttpServer { |
71 | 84 | move |request: HttpRequest| { |
72 | 85 | let store = Arc::clone(&store); |
73 | 86 | async move { |
74 | | - let pattern = format!("*.*.REST.{}.{:?}", request.host, request.method); |
75 | | - let route = RequestRoute { |
76 | | - url: request.path.clone(), |
77 | | - }; |
78 | | - |
79 | | - match store.get_possible_flow_match(pattern, route).await { |
80 | | - FlowIdentifyResult::Single(flow) => { |
81 | | - execute_flow(flow, request, store).await |
| 87 | + //Get slug => host/slug/real_path |
| 88 | + |
| 89 | + let splits: Vec<_> = request.path.split("/").collect(); |
| 90 | + let first = splits.first(); |
| 91 | + |
| 92 | + if let Some(slug) = first { |
| 93 | + let pattern = format!("REST.{}.*", slug); |
| 94 | + let route = RequestRoute { |
| 95 | + url: request.path.clone(), |
| 96 | + }; |
| 97 | + |
| 98 | + match store.get_possible_flow_match(pattern, route).await { |
| 99 | + FlowIdentifyResult::Single(flow) => { |
| 100 | + print!("Found flow: {}", flow.flow_id); |
| 101 | + execute_flow(flow, request, store).await |
| 102 | + } |
| 103 | + _ => Some(HttpResponse::internal_server_error( |
| 104 | + format!("No flow found for path: {}", request.path), |
| 105 | + HashMap::new(), |
| 106 | + )), |
82 | 107 | } |
83 | | - _ => Some(HttpResponse::internal_server_error( |
| 108 | + } else { |
| 109 | + Some(HttpResponse::internal_server_error( |
84 | 110 | format!("No flow found for path: {}", request.path), |
85 | 111 | HashMap::new(), |
86 | | - )), |
| 112 | + )) |
87 | 113 | } |
88 | 114 | } |
89 | 115 | } |
|
0 commit comments