mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-19 14:24:47 -07:00
server: reorg
This commit is contained in:
@@ -1,35 +0,0 @@
|
|||||||
use aide::axum::ApiRouter;
|
|
||||||
|
|
||||||
use crate::AppState;
|
|
||||||
|
|
||||||
mod addrs;
|
|
||||||
mod blocks;
|
|
||||||
mod fees;
|
|
||||||
mod general;
|
|
||||||
mod mempool;
|
|
||||||
mod mining;
|
|
||||||
mod transactions;
|
|
||||||
|
|
||||||
use addrs::AddrRoutes;
|
|
||||||
use blocks::BlockRoutes;
|
|
||||||
use fees::FeesRoutes;
|
|
||||||
use general::GeneralRoutes;
|
|
||||||
use mempool::MempoolRoutes;
|
|
||||||
use mining::MiningRoutes;
|
|
||||||
use transactions::TxRoutes;
|
|
||||||
|
|
||||||
pub trait MempoolSpaceRoutes {
|
|
||||||
fn add_mempool_space_routes(self) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MempoolSpaceRoutes for ApiRouter<AppState> {
|
|
||||||
fn add_mempool_space_routes(self) -> Self {
|
|
||||||
self.add_general_routes()
|
|
||||||
.add_addr_routes()
|
|
||||||
.add_block_routes()
|
|
||||||
.add_mining_routes()
|
|
||||||
.add_fees_routes()
|
|
||||||
.add_mempool_routes()
|
|
||||||
.add_tx_routes()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,24 +14,36 @@ use axum::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
Error,
|
Error,
|
||||||
api::{
|
api::{
|
||||||
mempool_space::MempoolSpaceRoutes, metrics::ApiMetricsLegacyRoutes,
|
metrics::ApiMetricsLegacyRoutes, series::ApiSeriesRoutes,
|
||||||
series::ApiSeriesRoutes, series_legacy::ApiSeriesLegacyRoutes, server::ServerRoutes,
|
series_legacy::ApiSeriesLegacyRoutes, server::ServerRoutes, urpd::ApiUrpdRoutes,
|
||||||
urpd::ApiUrpdRoutes,
|
|
||||||
},
|
},
|
||||||
extended::{ResponseExtended, TransformResponseExtended},
|
extended::{ResponseExtended, TransformResponseExtended},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::AppState;
|
use super::AppState;
|
||||||
|
|
||||||
mod mempool_space;
|
mod addrs;
|
||||||
|
mod blocks;
|
||||||
|
mod fees;
|
||||||
|
mod general;
|
||||||
|
mod mempool;
|
||||||
mod metrics;
|
mod metrics;
|
||||||
|
mod mining;
|
||||||
mod openapi;
|
mod openapi;
|
||||||
mod series;
|
mod series;
|
||||||
mod series_legacy;
|
mod series_legacy;
|
||||||
mod server;
|
mod server;
|
||||||
|
mod transactions;
|
||||||
mod urpd;
|
mod urpd;
|
||||||
|
|
||||||
|
use addrs::AddrRoutes;
|
||||||
|
use blocks::BlockRoutes;
|
||||||
|
use fees::FeesRoutes;
|
||||||
|
use general::GeneralRoutes;
|
||||||
|
use mempool::MempoolRoutes;
|
||||||
|
use mining::MiningRoutes;
|
||||||
pub use openapi::*;
|
pub use openapi::*;
|
||||||
|
use transactions::TxRoutes;
|
||||||
|
|
||||||
pub trait ApiRoutes {
|
pub trait ApiRoutes {
|
||||||
fn add_api_routes(self) -> Self;
|
fn add_api_routes(self) -> Self;
|
||||||
@@ -44,7 +56,13 @@ impl ApiRoutes for ApiRouter<AppState> {
|
|||||||
.add_series_legacy_routes()
|
.add_series_legacy_routes()
|
||||||
.add_urpd_routes()
|
.add_urpd_routes()
|
||||||
.add_metrics_legacy_routes()
|
.add_metrics_legacy_routes()
|
||||||
.add_mempool_space_routes()
|
.add_general_routes()
|
||||||
|
.add_addr_routes()
|
||||||
|
.add_block_routes()
|
||||||
|
.add_mining_routes()
|
||||||
|
.add_fees_routes()
|
||||||
|
.add_mempool_routes()
|
||||||
|
.add_tx_routes()
|
||||||
.route("/api/server", get(Redirect::temporary("/api#tag/server")))
|
.route("/api/server", get(Redirect::temporary("/api#tag/server")))
|
||||||
.api_route(
|
.api_route(
|
||||||
"/openapi.json",
|
"/openapi.json",
|
||||||
|
|||||||
1
crates/brk_server/src/cache/mod.rs
vendored
1
crates/brk_server/src/cache/mod.rs
vendored
@@ -17,4 +17,3 @@ pub use params::CacheParams;
|
|||||||
pub use strategy::CacheStrategy;
|
pub use strategy::CacheStrategy;
|
||||||
|
|
||||||
pub(crate) use mode::init;
|
pub(crate) use mode::init;
|
||||||
pub(crate) use params::CC_ERROR;
|
|
||||||
|
|||||||
9
crates/brk_server/src/cache/params.rs
vendored
9
crates/brk_server/src/cache/params.rs
vendored
@@ -14,7 +14,7 @@ const CC: &str = "public, no-cache, stale-if-error=86400";
|
|||||||
|
|
||||||
// Errors: short, must-revalidate, no `stale-if-error` (we don't want a 24h-old
|
// Errors: short, must-revalidate, no `stale-if-error` (we don't want a 24h-old
|
||||||
// error served when origin recovers). Same string for browser and CDN.
|
// error served when origin recovers). Same string for browser and CDN.
|
||||||
pub(crate) const CC_ERROR: &str = "public, max-age=1, must-revalidate";
|
const CC_ERROR: &str = "public, max-age=1, must-revalidate";
|
||||||
|
|
||||||
/// Resolved cache parameters: an ETag plus the two Cache-Control directives.
|
/// Resolved cache parameters: an ETag plus the two Cache-Control directives.
|
||||||
pub struct CacheParams {
|
pub struct CacheParams {
|
||||||
@@ -97,6 +97,13 @@ impl CacheParams {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Apply error cache-control headers without an ETag. Used for synthesized
|
||||||
|
/// errors (panics, fallback handlers) that have no resource etag.
|
||||||
|
pub fn apply_error_cache_control(headers: &mut HeaderMap) {
|
||||||
|
headers.insert_cache_control(CC_ERROR);
|
||||||
|
headers.insert_cdn_cache_control(CC_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn matches_etag(&self, headers: &HeaderMap) -> bool {
|
pub fn matches_etag(&self, headers: &HeaderMap) -> bool {
|
||||||
headers.has_etag(self.etag.as_str())
|
headers.has_etag(self.etag.as_str())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,7 @@ use brk_error::Error as BrkError;
|
|||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{cache::CacheParams, etag::Etag};
|
||||||
cache::{CC_ERROR, CacheParams},
|
|
||||||
etag::Etag,
|
|
||||||
extended::HeaderMapExtended,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Server result type with Error that implements IntoResponse.
|
/// Server result type with Error that implements IntoResponse.
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
@@ -145,7 +141,13 @@ impl Error {
|
|||||||
|
|
||||||
pub(crate) fn into_response_with_etag(self, etag: Etag) -> Response {
|
pub(crate) fn into_response_with_etag(self, etag: Etag) -> Response {
|
||||||
let params = CacheParams::error(etag);
|
let params = CacheParams::error(etag);
|
||||||
let mut response = self.into_response();
|
let body = build_error_body(self.status, self.code, self.message);
|
||||||
|
let mut response = (
|
||||||
|
self.status,
|
||||||
|
[(header::CONTENT_TYPE, "application/problem+json")],
|
||||||
|
body,
|
||||||
|
)
|
||||||
|
.into_response();
|
||||||
params.apply_to(response.headers_mut());
|
params.apply_to(response.headers_mut());
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
@@ -174,9 +176,7 @@ impl IntoResponse for Error {
|
|||||||
body,
|
body,
|
||||||
)
|
)
|
||||||
.into_response();
|
.into_response();
|
||||||
let h = response.headers_mut();
|
CacheParams::apply_error_cache_control(response.headers_mut());
|
||||||
h.insert_cache_control(CC_ERROR);
|
|
||||||
h.insert_cdn_cache_control(CC_ERROR);
|
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
use schemars::JsonSchema;
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
use brk_types::Limit;
|
|
||||||
|
|
||||||
#[derive(Deserialize, JsonSchema)]
|
|
||||||
pub struct LimitParam {
|
|
||||||
#[serde(default)]
|
|
||||||
pub limit: Limit,
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@ mod blockhash_param;
|
|||||||
mod blockhash_start_index;
|
mod blockhash_start_index;
|
||||||
mod blockhash_tx_index;
|
mod blockhash_tx_index;
|
||||||
mod height_param;
|
mod height_param;
|
||||||
mod limit_param;
|
|
||||||
mod pool_slug_param;
|
mod pool_slug_param;
|
||||||
mod series_param;
|
mod series_param;
|
||||||
mod time_period_param;
|
mod time_period_param;
|
||||||
@@ -24,7 +23,6 @@ pub use blockhash_param::*;
|
|||||||
pub use blockhash_start_index::*;
|
pub use blockhash_start_index::*;
|
||||||
pub use blockhash_tx_index::*;
|
pub use blockhash_tx_index::*;
|
||||||
pub use height_param::*;
|
pub use height_param::*;
|
||||||
pub use limit_param::*;
|
|
||||||
pub use pool_slug_param::*;
|
pub use pool_slug_param::*;
|
||||||
pub use series_param::*;
|
pub use series_param::*;
|
||||||
pub use time_period_param::*;
|
pub use time_period_param::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user