Supporting /api/ping for dapps server (#1543)
* Refactoring dapps to support API endpoints. * Using ContentHandler for unauthorized requests * Extracting url stuff * Adding ping endpoint * CORS support for ping request * Fixing url.is_none() * minor formatting fix [ci:skip]
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
use serde::Serialize;
|
||||
use serde_json;
|
||||
use endpoint::Handler;
|
||||
use handlers::ContentHandler;
|
||||
use handlers::{ContentHandler, EchoHandler};
|
||||
|
||||
pub fn as_json<T : Serialize>(val: &T) -> Box<Handler> {
|
||||
Box::new(ContentHandler::ok(serde_json::to_string(val).unwrap(), "application/json".to_owned()))
|
||||
@@ -26,3 +26,11 @@ pub fn as_json<T : Serialize>(val: &T) -> Box<Handler> {
|
||||
pub fn as_json_error<T : Serialize>(val: &T) -> Box<Handler> {
|
||||
Box::new(ContentHandler::not_found(serde_json::to_string(val).unwrap(), "application/json".to_owned()))
|
||||
}
|
||||
|
||||
pub fn ping_response(local_domain: &str) -> Box<Handler> {
|
||||
Box::new(EchoHandler::cors(vec![
|
||||
format!("http://{}", local_domain),
|
||||
// Allow CORS calls also for localhost
|
||||
format!("http://{}", local_domain.replace("127.0.0.1", "localhost")),
|
||||
]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user