From ffcb37677f6fabb9af279e7cd9a282cde6ef02a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Sat, 22 Oct 2016 16:58:35 +0200 Subject: [PATCH] Local dapps embeddable on signer port --- dapps/src/apps/fetcher.rs | 12 ++++++++---- dapps/src/apps/fs.rs | 4 ++-- dapps/src/apps/mod.rs | 2 +- dapps/src/lib.rs | 2 +- dapps/src/page/local.rs | 9 ++++++--- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/dapps/src/apps/fetcher.rs b/dapps/src/apps/fetcher.rs index 9d66276eaed..df51f31de33 100644 --- a/dapps/src/apps/fetcher.rs +++ b/dapps/src/apps/fetcher.rs @@ -46,6 +46,7 @@ pub struct ContentFetcher { resolver: R, cache: Arc>, sync: Arc, + embeddable_at: Option, } impl Drop for ContentFetcher { @@ -57,7 +58,7 @@ impl Drop for ContentFetcher { impl ContentFetcher { - pub fn new(resolver: R, sync_status: Arc) -> Self { + pub fn new(resolver: R, sync_status: Arc, embeddable_at: Option) -> Self { let mut dapps_path = env::temp_dir(); dapps_path.push(random_filename()); @@ -66,6 +67,7 @@ impl ContentFetcher { resolver: resolver, sync: sync_status, cache: Arc::new(Mutex::new(ContentCache::default())), + embeddable_at: embeddable_at, } } @@ -150,6 +152,7 @@ impl ContentFetcher { id: content_id.clone(), dapps_path: self.dapps_path.clone(), on_done: Box::new(on_done), + embeddable_at: self.embeddable_at, } ); @@ -271,6 +274,7 @@ struct DappInstaller { id: String, dapps_path: PathBuf, on_done: Box) + Send>, + embeddable_at: Option, } impl DappInstaller { @@ -363,7 +367,7 @@ impl ContentValidator for DappInstaller { try!(manifest_file.write_all(manifest_str.as_bytes())); // Create endpoint - let app = LocalPageEndpoint::new(target, manifest.clone().into()); + let app = LocalPageEndpoint::new(target, manifest.clone().into(), self.embeddable_at); // Return modified app manifest Ok((manifest.id.clone(), app)) @@ -396,14 +400,14 @@ mod tests { fn should_true_if_contains_the_app() { // given let path = env::temp_dir(); - let fetcher = ContentFetcher::new(FakeResolver, Arc::new(|| false)); + let fetcher = ContentFetcher::new(FakeResolver, Arc::new(|| false), None); let handler = LocalPageEndpoint::new(path, EndpointInfo { name: "fake".into(), description: "".into(), version: "".into(), author: "".into(), icon_url: "".into(), - }); + }, None); // when fetcher.set_status("test", ContentStatus::Ready(handler)); diff --git a/dapps/src/apps/fs.rs b/dapps/src/apps/fs.rs index 4728757de07..e7a11fc8e5f 100644 --- a/dapps/src/apps/fs.rs +++ b/dapps/src/apps/fs.rs @@ -97,12 +97,12 @@ fn read_manifest(name: &str, mut path: PathBuf) -> EndpointInfo { }) } -pub fn local_endpoints(dapps_path: String) -> Endpoints { +pub fn local_endpoints(dapps_path: String, signer_port: Option) -> Endpoints { let mut pages = Endpoints::new(); for dapp in local_dapps(dapps_path) { pages.insert( dapp.id, - Box::new(LocalPageEndpoint::new(dapp.path, dapp.info)) + Box::new(LocalPageEndpoint::new(dapp.path, dapp.info, signer_port)) ); } pages diff --git a/dapps/src/apps/mod.rs b/dapps/src/apps/mod.rs index 40ddb706497..a7b97d37c54 100644 --- a/dapps/src/apps/mod.rs +++ b/dapps/src/apps/mod.rs @@ -47,7 +47,7 @@ pub fn utils() -> Box { pub fn all_endpoints(dapps_path: String, signer_port: Option) -> Endpoints { // fetch fs dapps at first to avoid overwriting builtins - let mut pages = fs::local_endpoints(dapps_path); + let mut pages = fs::local_endpoints(dapps_path, signer_port); // NOTE [ToDr] Dapps will be currently embeded on 8180 insert::(&mut pages, "ui", Embeddable::Yes(signer_port)); diff --git a/dapps/src/lib.rs b/dapps/src/lib.rs index 00c8b275e7a..0041dbedf17 100644 --- a/dapps/src/lib.rs +++ b/dapps/src/lib.rs @@ -218,7 +218,7 @@ impl Server { ) -> Result { let panic_handler = Arc::new(Mutex::new(None)); let authorization = Arc::new(authorization); - let content_fetcher = Arc::new(apps::fetcher::ContentFetcher::new(apps::urlhint::URLHintContract::new(registrar), sync_status)); + let content_fetcher = Arc::new(apps::fetcher::ContentFetcher::new(apps::urlhint::URLHintContract::new(registrar), sync_status, signer_port)); let endpoints = Arc::new(apps::all_endpoints(dapps_path, signer_port.clone())); let cors_domains = Self::cors_domains(signer_port); diff --git a/dapps/src/page/local.rs b/dapps/src/page/local.rs index e702fe4d567..5390f5aac49 100644 --- a/dapps/src/page/local.rs +++ b/dapps/src/page/local.rs @@ -26,14 +26,16 @@ pub struct LocalPageEndpoint { path: PathBuf, mime: Option, info: Option, + embeddable_at: Option, } impl LocalPageEndpoint { - pub fn new(path: PathBuf, info: EndpointInfo) -> Self { + pub fn new(path: PathBuf, info: EndpointInfo, embeddable_at: Option) -> Self { LocalPageEndpoint { path: path, mime: None, info: Some(info), + embeddable_at: embeddable_at, } } @@ -42,6 +44,7 @@ impl LocalPageEndpoint { path: path, mime: Some(mime), info: None, + embeddable_at: None, } } @@ -62,7 +65,7 @@ impl Endpoint for LocalPageEndpoint { prefix: None, path: path, file: handler::ServedFile::new(None), - safe_to_embed_at_port: None, + safe_to_embed_at_port: self.embeddable_at, }) } else { Box::new(handler::PageHandler { @@ -70,7 +73,7 @@ impl Endpoint for LocalPageEndpoint { prefix: None, path: path, file: handler::ServedFile::new(None), - safe_to_embed_at_port: None, + safe_to_embed_at_port: self.embeddable_at, }) } }