|
1 | 1 | use actix_web::HttpRequest;
|
2 | 2 | use app_state::AppState;
|
3 |
| -use presets::m2::parse::get_deps_from_str; |
4 | 3 | use presets::m2::preset_m2::FutResp;
|
| 4 | +use presets::m2::requirejs_config::RequireJsClientConfig; |
5 | 5 | use proxy_utils::apply_to_proxy_body;
|
6 | 6 |
|
7 | 7 | ///
|
8 |
| -/// This handler has 2 purposes. |
9 |
| -/// |
10 |
| -/// First, it will record the incoming string from the Magento-generated |
| 8 | +/// This handler will record the incoming string from the Magento-generated |
11 | 9 | /// requirejs-config.js and use that to build up the 'deps' array. This is required
|
12 | 10 | /// since the client config that the client posts back does not include all original
|
13 | 11 | /// 'deps' (I'm not sure why)
|
14 | 12 | ///
|
15 |
| -/// Secondly, it will append a small piece of JS to the end of the file in order |
16 |
| -/// to send back the configuration. |
17 |
| -/// |
18 | 13 | pub fn handle(original_request: &HttpRequest<AppState>) -> FutResp {
|
19 | 14 | let client_config_clone = original_request.state().rjs_client_config.clone();
|
20 |
| - apply_to_proxy_body(&original_request, move |mut b| { |
| 15 | + apply_to_proxy_body(&original_request, move |b| { |
21 | 16 | let c2 = client_config_clone.clone();
|
22 |
| - if let Ok(deps) = get_deps_from_str(&b) { |
23 |
| - let mut w = c2.lock().expect("unwraped"); |
24 |
| - w.deps = deps; |
25 |
| - }; |
26 |
| - b.push_str(include_str!("../static/post_config.js")); |
| 17 | + if let Ok(rjs) = RequireJsClientConfig::from_generated_string(b.to_string()) { |
| 18 | + let mut w = c2.lock().expect("unwrapped client_config_clone"); |
| 19 | + *w = rjs |
| 20 | + } |
27 | 21 | b
|
28 | 22 | })
|
29 | 23 | }
|
0 commit comments