-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from BrowserSync/inject-params
control injections
- Loading branch information
Showing
13 changed files
with
209 additions
and
8 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
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
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
13 changes: 13 additions & 0 deletions
13
...s/bsnext_core/src/snapshots/bsnext_core__dynamic_query_params__test__deserializing-2.snap
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
source: crates/bsnext_core/src/dynamic_query_params.rs | ||
expression: query_with_bool | ||
--- | ||
DynamicQueryParams { | ||
delay: None, | ||
cache: None, | ||
inject: Some( | ||
Other( | ||
"false", | ||
), | ||
), | ||
} |
17 changes: 17 additions & 0 deletions
17
crates/bsnext_core/src/snapshots/bsnext_core__dynamic_query_params__test__deserializing.snap
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
source: crates/bsnext_core/src/dynamic_query_params.rs | ||
expression: query_with_named | ||
--- | ||
DynamicQueryParams { | ||
delay: Some( | ||
2000, | ||
), | ||
cache: Some( | ||
Prevent, | ||
), | ||
inject: Some( | ||
BuiltinStrings( | ||
JsConnector, | ||
), | ||
), | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::injector_guard::ByteReplacer; | ||
use crate::RespMod; | ||
use axum::extract::Request; | ||
use bsnext_guards::route_guard::RouteGuard; | ||
use http::Response; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct JsConnector; | ||
|
||
impl RouteGuard for JsConnector { | ||
fn accept_req(&self, _req: &Request) -> bool { | ||
true | ||
} | ||
|
||
fn accept_res<T>(&self, res: &Response<T>) -> bool { | ||
let is_js = RespMod::is_js(res); | ||
tracing::trace!("is_js: {}", is_js); | ||
is_js | ||
} | ||
} | ||
impl ByteReplacer for JsConnector { | ||
fn apply(&self, body: &'_ str) -> Option<String> { | ||
let footer = format!( | ||
r#"{body}; | ||
// this was injected by the Browsersync Live Js Connector | ||
;import('/__bs_js').catch(console.error); | ||
"# | ||
); | ||
Some(footer) | ||
} | ||
} |
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
1 change: 0 additions & 1 deletion
1
...om_paths__test__input_from_paths.snap.new → ...t_from_paths__test__input_from_paths.snap
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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("hello from script2.js"); |
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