2016-02-18 14:36:59 +01:00
|
|
|
use self::jsonrpc_core::{IoHandler, IoDelegate};
|
|
|
|
|
|
|
|
pub mod v1;
|
|
|
|
|
|
|
|
/// Http server.
|
|
|
|
pub struct HttpServer {
|
|
|
|
handler: IoHandler,
|
|
|
|
threads: usize
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HttpServer {
|
|
|
|
/// Construct new http server object with given number of threads.
|
|
|
|
pub fn new(threads: usize) -> HttpServer {
|
|
|
|
HttpServer {
|
|
|
|
handler: IoHandler::new(),
|
|
|
|
threads: threads
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add io delegate.
|
|
|
|
pub fn add_delegate<D>(&mut self, delegate: IoDelegate<D>) where D: Send + Sync + 'static {
|
|
|
|
self.handler.add_delegate(delegate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Start server asynchronously in new thread
|
2016-02-22 13:41:38 +01:00
|
|
|
pub fn start_async(self, addr: &str, cors_domain: &str) {
|
2016-02-18 14:36:59 +01:00
|
|
|
let server = jsonrpc_http_server::Server::new(self.handler, self.threads);
|
2016-02-22 13:41:38 +01:00
|
|
|
server.start_async(addr, jsonrpc_http_server::AccessControlAllowOrigin::Value(cors_domain.to_owned()))
|
2016-02-18 14:36:59 +01:00
|
|
|
}
|
|
|
|
}
|