Skip to content

Commit 19d44a5

Browse files
committed
fix: parse the entire requirejs-config.js file - fixes #32
1 parent 25b8457 commit 19d44a5

File tree

6 files changed

+1329
-204
lines changed

6 files changed

+1329
-204
lines changed
+7-13
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
use actix_web::HttpRequest;
22
use app_state::AppState;
3-
use presets::m2::parse::get_deps_from_str;
43
use presets::m2::preset_m2::FutResp;
4+
use presets::m2::requirejs_config::RequireJsClientConfig;
55
use proxy_utils::apply_to_proxy_body;
66

77
///
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
119
/// requirejs-config.js and use that to build up the 'deps' array. This is required
1210
/// since the client config that the client posts back does not include all original
1311
/// 'deps' (I'm not sure why)
1412
///
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-
///
1813
pub fn handle(original_request: &HttpRequest<AppState>) -> FutResp {
1914
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| {
2116
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+
}
2721
b
2822
})
2923
}

0 commit comments

Comments
 (0)