31 lines
798 B
Rust
31 lines
798 B
Rust
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
|
|
pub fn start_async(self, addr: &str, cors_domain: &str) {
|
|
let server = jsonrpc_http_server::Server::new(self.handler, self.threads);
|
|
server.start_async(addr, jsonrpc_http_server::AccessControlAllowOrigin::Value(cors_domain.to_owned()))
|
|
}
|
|
}
|