2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-04-07 12:10:26 +02:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-01-06 16:05:58 +01:00
|
|
|
use std::path::PathBuf;
|
2016-12-27 11:15:02 +01:00
|
|
|
use std::sync::Arc;
|
2016-05-13 18:40:20 +02:00
|
|
|
use endpoint::{Endpoints, Endpoint};
|
2016-04-14 20:38:48 +02:00
|
|
|
use page::PageEndpoint;
|
2016-05-12 14:45:09 +02:00
|
|
|
use proxypac::ProxyPac;
|
2016-12-22 18:26:39 +01:00
|
|
|
use web::Web;
|
|
|
|
use fetch::Fetch;
|
2016-10-22 15:21:41 +02:00
|
|
|
use parity_dapps::WebApp;
|
2016-12-22 18:26:39 +01:00
|
|
|
use parity_reactor::Remote;
|
2016-12-27 11:15:02 +01:00
|
|
|
use {WebProxyTokens};
|
2016-04-07 12:10:26 +02:00
|
|
|
|
2016-08-30 14:04:52 +02:00
|
|
|
mod cache;
|
2016-06-03 11:51:11 +02:00
|
|
|
mod fs;
|
2016-08-18 12:19:09 +02:00
|
|
|
pub mod fetcher;
|
|
|
|
pub mod manifest;
|
2016-06-03 11:51:11 +02:00
|
|
|
|
2016-10-17 11:56:42 +02:00
|
|
|
extern crate parity_ui;
|
2016-05-21 15:27:55 +02:00
|
|
|
|
2016-10-22 15:21:41 +02:00
|
|
|
pub const HOME_PAGE: &'static str = "home";
|
2016-12-22 18:26:39 +01:00
|
|
|
pub const DAPPS_DOMAIN: &'static str = ".parity";
|
|
|
|
pub const RPC_PATH: &'static str = "rpc";
|
|
|
|
pub const API_PATH: &'static str = "api";
|
|
|
|
pub const UTILS_PATH: &'static str = "parity-utils";
|
|
|
|
pub const WEB_PATH: &'static str = "web";
|
2017-01-16 10:49:27 +01:00
|
|
|
pub const URL_REFERER: &'static str = "__referer=";
|
2016-05-13 18:40:20 +02:00
|
|
|
|
|
|
|
pub fn utils() -> Box<Endpoint> {
|
2016-10-22 15:21:41 +02:00
|
|
|
Box::new(PageEndpoint::with_prefix(parity_ui::App::default(), UTILS_PATH.to_owned()))
|
2016-05-13 18:40:20 +02:00
|
|
|
}
|
|
|
|
|
2016-12-27 11:15:02 +01:00
|
|
|
pub fn all_endpoints<F: Fetch>(
|
2017-01-06 16:05:58 +01:00
|
|
|
dapps_path: PathBuf,
|
|
|
|
extra_dapps: Vec<PathBuf>,
|
2016-12-27 11:15:02 +01:00
|
|
|
signer_address: Option<(String, u16)>,
|
|
|
|
web_proxy_tokens: Arc<WebProxyTokens>,
|
|
|
|
remote: Remote,
|
|
|
|
fetch: F,
|
|
|
|
) -> Endpoints {
|
2016-06-03 11:51:11 +02:00
|
|
|
// fetch fs dapps at first to avoid overwriting builtins
|
2016-11-09 19:41:47 +01:00
|
|
|
let mut pages = fs::local_endpoints(dapps_path, signer_address.clone());
|
2017-01-06 16:05:58 +01:00
|
|
|
for path in extra_dapps {
|
|
|
|
if let Some((id, endpoint)) = fs::local_endpoint(path.clone(), signer_address.clone()) {
|
|
|
|
pages.insert(id, endpoint);
|
|
|
|
} else {
|
|
|
|
warn!(target: "dapps", "Ignoring invalid dapp at {}", path.display());
|
|
|
|
}
|
|
|
|
}
|
2016-10-19 11:02:21 +02:00
|
|
|
|
2016-10-17 11:56:42 +02:00
|
|
|
// NOTE [ToDr] Dapps will be currently embeded on 8180
|
2016-11-09 19:41:47 +01:00
|
|
|
insert::<parity_ui::App>(&mut pages, "ui", Embeddable::Yes(signer_address.clone()));
|
2016-12-27 11:15:02 +01:00
|
|
|
pages.insert("proxy".into(), ProxyPac::boxed(signer_address.clone()));
|
|
|
|
pages.insert(WEB_PATH.into(), Web::boxed(signer_address.clone(), web_proxy_tokens.clone(), remote.clone(), fetch.clone()));
|
2016-06-03 11:51:11 +02:00
|
|
|
|
2016-04-07 12:10:26 +02:00
|
|
|
pages
|
|
|
|
}
|
|
|
|
|
2016-10-22 15:21:41 +02:00
|
|
|
fn insert<T : WebApp + Default + 'static>(pages: &mut Endpoints, id: &str, embed_at: Embeddable) {
|
|
|
|
pages.insert(id.to_owned(), Box::new(match embed_at {
|
2016-11-09 19:41:47 +01:00
|
|
|
Embeddable::Yes(address) => PageEndpoint::new_safe_to_embed(T::default(), address),
|
2016-10-22 15:21:41 +02:00
|
|
|
Embeddable::No => PageEndpoint::new(T::default()),
|
|
|
|
}));
|
2016-04-07 12:10:26 +02:00
|
|
|
}
|
2016-10-17 11:56:42 +02:00
|
|
|
|
2016-10-22 15:21:41 +02:00
|
|
|
enum Embeddable {
|
2016-11-09 19:41:47 +01:00
|
|
|
Yes(Option<(String, u16)>),
|
2016-10-22 15:21:41 +02:00
|
|
|
#[allow(dead_code)]
|
|
|
|
No,
|
2016-10-17 11:56:42 +02:00
|
|
|
}
|