Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parse the entire requirejs-config.js file - fixes #32 #33

Merged
merged 1 commit into from
Oct 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
})
}
Loading