#![warn(missing_docs)]
pub mod actions;
pub mod capture;
pub mod config;
#[doc(hidden)]
pub mod constants;
pub mod error;
#[doc(hidden)]
pub mod event_stream;
pub mod health;
#[cfg(feature = "mirror")]
#[doc(hidden)]
pub mod mirror;
#[doc(hidden)]
pub mod retention;
#[doc(hidden)]
pub mod sequence;
pub mod server;
#[doc(hidden)]
pub mod shard_iterator;
pub mod store;
pub mod types;
#[doc(hidden)]
pub mod util;
#[doc(hidden)]
pub mod validation;
use axum::Router;
use axum::middleware;
use axum::routing::{any, get};
use store::{Store, StoreOptions};
#[cfg(feature = "access-log")]
use tower_http::trace::{DefaultMakeSpan, DefaultOnResponse, TraceLayer};
pub fn create_app(options: StoreOptions) -> (Router, Store) {
create_app_with_capture(options, None)
}
pub fn create_app_with_capture(
options: StoreOptions,
capture: Option<capture::CaptureWriter>,
) -> (Router, Store) {
let store = Store::with_capture(options.clone(), capture);
let app = Router::new()
.route("/_health", get(health::health))
.route("/_health/live", get(health::live))
.route("/_health/ready", get(health::ready))
.fallback(any(server::handler))
.with_state(store.clone())
.layer(middleware::from_fn(server::kinesis_413_middleware));
#[cfg(feature = "access-log")]
let app = app.layer(
TraceLayer::new_for_http()
.make_span_with(DefaultMakeSpan::new().level(tracing::Level::INFO))
.on_response(DefaultOnResponse::new().level(tracing::Level::INFO)),
);
if options.retention_check_interval_secs > 0 {
let reaper_store = store.clone();
tokio::spawn(retention::run_reaper(
reaper_store,
options.retention_check_interval_secs,
));
}
(app, store)
}