From c3ba5ad5ebe1d5bb28ed0a340af93e8547b1c5bc Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Wed, 7 Apr 2021 01:08:31 +0300 Subject: Initial commit --- src/custom_filters.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/custom_filters.rs (limited to 'src/custom_filters.rs') diff --git a/src/custom_filters.rs b/src/custom_filters.rs new file mode 100644 index 0000000..86a78d4 --- /dev/null +++ b/src/custom_filters.rs @@ -0,0 +1,21 @@ +// Common filters ment to be shared between many endpoints + +use std::convert::Infallible; +use warp::{Filter, Rejection}; + +use crate::schema::{Db, Transaction}; // `Block` coming later + +// Database context for routes +pub fn with_db(db: Db) -> impl Filter + Clone { + warp::any().map(move || db.clone()) +} + +// Optional query params to allow pagination +// pub fn list_options() -> impl Filter + Clone { +// warp::query::() +// } + +// Accept only JSON body and reject big payloads +pub fn json_body() -> impl Filter + Clone { + warp::body::content_length_limit(1024 * 32).and(warp::body::json()) +} -- cgit v1.2.3-70-g09d2