Skip to content

Commit

Permalink
fix: parse the entire requirejs-config.js file - fixes #32
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Oct 27, 2018
1 parent 25b8457 commit 19d44a5
Show file tree
Hide file tree
Showing 6 changed files with 1,329 additions and 204 deletions.
20 changes: 7 additions & 13 deletions src/lib/presets/m2/handlers/config_capture.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
use actix_web::HttpRequest;
use app_state::AppState;
use presets::m2::parse::get_deps_from_str;
use presets::m2::preset_m2::FutResp;
use presets::m2::requirejs_config::RequireJsClientConfig;
use proxy_utils::apply_to_proxy_body;

///
/// This handler has 2 purposes.
///
/// First, it will record the incoming string from the Magento-generated
/// This handler will record the incoming string from the Magento-generated
/// requirejs-config.js and use that to build up the 'deps' array. This is required
/// since the client config that the client posts back does not include all original
/// 'deps' (I'm not sure why)
///
/// Secondly, it will append a small piece of JS to the end of the file in order
/// to send back the configuration.
///
pub fn handle(original_request: &HttpRequest<AppState>) -> FutResp {
let client_config_clone = original_request.state().rjs_client_config.clone();
apply_to_proxy_body(&original_request, move |mut b| {
apply_to_proxy_body(&original_request, move |b| {
let c2 = client_config_clone.clone();
if let Ok(deps) = get_deps_from_str(&b) {
let mut w = c2.lock().expect("unwraped");
w.deps = deps;
};
b.push_str(include_str!("../static/post_config.js"));
if let Ok(rjs) = RequireJsClientConfig::from_generated_string(b.to_string()) {
let mut w = c2.lock().expect("unwrapped client_config_clone");
*w = rjs
}
b
})
}

0 comments on commit 19d44a5

Please sign in to comment.