mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 15:19:58 -07:00
server: server struct
This commit is contained in:
@@ -3,9 +3,9 @@ use axum::{Router, routing::get};
|
||||
use super::AppState;
|
||||
|
||||
mod explorer;
|
||||
mod vecs;
|
||||
mod query;
|
||||
|
||||
pub use vecs::DTS;
|
||||
pub use query::DTS;
|
||||
|
||||
pub trait ApiRoutes {
|
||||
fn add_api_routes(self) -> Self;
|
||||
@@ -13,6 +13,6 @@ pub trait ApiRoutes {
|
||||
|
||||
impl ApiRoutes for Router<AppState> {
|
||||
fn add_api_routes(self) -> Self {
|
||||
self.route("/api/vecs", get(vecs::handler))
|
||||
self.route("/api/query", get(query::handler))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ use axum::{
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use brk_query::{Format, Index, Output, Params};
|
||||
use color_eyre::eyre::eyre;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::{log_result, traits::HeaderMapExtended};
|
||||
|
||||
@@ -26,17 +24,15 @@ pub async fn handler(
|
||||
) -> Response {
|
||||
let instant = Instant::now();
|
||||
|
||||
let path = uri.path();
|
||||
|
||||
match req_to_response_res(headers, query, app_state) {
|
||||
Ok(response) => {
|
||||
log_result(response.status(), path, instant);
|
||||
log_result(response.status(), &uri, instant);
|
||||
response
|
||||
}
|
||||
Err(error) => {
|
||||
let mut response =
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, error.to_string()).into_response();
|
||||
log_result(response.status(), path, instant);
|
||||
log_result(response.status(), &uri, instant);
|
||||
response.headers_mut().insert_cors();
|
||||
response
|
||||
}
|
||||
Reference in New Issue
Block a user