-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: parse the entire requirejs-config.js file - fixes #32
- Loading branch information
1 parent
25b8457
commit 19d44a5
Showing
6 changed files
with
1,329 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
} |
Oops, something went wrong.