Enable access to WebSockets for dapps.
This commit is contained in:
parent
2472a2be0c
commit
48ac6cbcf8
@ -862,6 +862,7 @@ impl Configuration {
|
||||
|
||||
fn ws_config(&self) -> Result<WsConfiguration, String> {
|
||||
let ui = self.ui_config();
|
||||
let http = self.http_config()?;
|
||||
|
||||
let conf = WsConfiguration {
|
||||
enabled: self.ws_enabled(),
|
||||
@ -873,6 +874,7 @@ impl Configuration {
|
||||
signer_path: self.directories().signer.into(),
|
||||
support_token_api: !self.args.flag_public_node,
|
||||
ui_address: ui.address(),
|
||||
dapps_address: http.address(),
|
||||
};
|
||||
|
||||
Ok(conf)
|
||||
|
@ -150,6 +150,7 @@ pub struct WsConfiguration {
|
||||
pub signer_path: PathBuf,
|
||||
pub support_token_api: bool,
|
||||
pub ui_address: Option<rpc::Host>,
|
||||
pub dapps_address: Option<rpc::Host>,
|
||||
}
|
||||
|
||||
impl Default for WsConfiguration {
|
||||
@ -165,6 +166,7 @@ impl Default for WsConfiguration {
|
||||
signer_path: replace_home(&data_dir, "$BASE/signer").into(),
|
||||
support_token_api: true,
|
||||
ui_address: Some("127.0.0.1:8180".into()),
|
||||
dapps_address: Some("127.0.0.1:8545".into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -220,8 +222,8 @@ pub fn new_ws<D: rpc_apis::Dependencies>(
|
||||
|
||||
let remote = deps.remote.clone();
|
||||
let ui_address = conf.ui_address.clone();
|
||||
let allowed_origins = into_domains(with_domain(conf.origins, domain, &ui_address));
|
||||
let allowed_hosts = into_domains(with_domain(conf.hosts, domain, &Some(url.clone().into())));
|
||||
let allowed_origins = into_domains(with_domain(conf.origins, domain, &ui_address, &conf.dapps_address));
|
||||
let allowed_hosts = into_domains(with_domain(conf.hosts, domain, &Some(url.clone().into()), &None));
|
||||
|
||||
let signer_path;
|
||||
let path = match conf.support_token_api && conf.ui_address.is_some() {
|
||||
@ -269,7 +271,7 @@ pub fn new_http<D: rpc_apis::Dependencies>(
|
||||
let remote = deps.remote.clone();
|
||||
|
||||
let cors_domains = into_domains(conf.cors);
|
||||
let allowed_hosts = into_domains(with_domain(conf.hosts, domain, &Some(url.clone().into())));
|
||||
let allowed_hosts = into_domains(with_domain(conf.hosts, domain, &Some(url.clone().into()), &None));
|
||||
|
||||
let start_result = rpc::start_http(
|
||||
&addr,
|
||||
@ -311,20 +313,27 @@ fn into_domains<T: From<String>>(items: Option<Vec<String>>) -> DomainsValidatio
|
||||
items.map(|vals| vals.into_iter().map(T::from).collect()).into()
|
||||
}
|
||||
|
||||
fn with_domain(items: Option<Vec<String>>, domain: &str, address: &Option<rpc::Host>) -> Option<Vec<String>> {
|
||||
fn with_domain(items: Option<Vec<String>>, domain: &str, ui_address: &Option<rpc::Host>, dapps_address: &Option<rpc::Host>) -> Option<Vec<String>> {
|
||||
fn extract_port(s: &str) -> Option<u16> {
|
||||
s.split(':').nth(1).and_then(|s| s.parse().ok())
|
||||
}
|
||||
|
||||
items.map(move |items| {
|
||||
let mut items = items.into_iter().collect::<HashSet<_>>();
|
||||
if let Some(host) = address.clone() {
|
||||
items.insert(host.to_string());
|
||||
items.insert(host.replace("127.0.0.1", "localhost"));
|
||||
items.insert(format!("http://*.{}", domain)); //proxypac
|
||||
if let Some(port) = extract_port(&*host) {
|
||||
items.insert(format!("http://*.{}:{}", domain, port));
|
||||
}
|
||||
{
|
||||
let mut add_hosts = |address: &Option<rpc::Host>| {
|
||||
if let Some(host) = address.clone() {
|
||||
items.insert(host.to_string());
|
||||
items.insert(host.replace("127.0.0.1", "localhost"));
|
||||
items.insert(format!("http://*.{}", domain)); //proxypac
|
||||
if let Some(port) = extract_port(&*host) {
|
||||
items.insert(format!("http://*.{}:{}", domain, port));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
add_hosts(ui_address);
|
||||
add_hosts(dapps_address);
|
||||
}
|
||||
items.into_iter().collect()
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user