nom-nom-nix-gc/src/filters/mod.rs

32 lines
1.1 KiB
Rust

use warp::Filter;
use crate::handlers;
use crate::models;
pub fn all(state: models::AppState) -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone + '_{
landing(state.clone())
.or(start_webauthn_registration(state.clone()))
.or(start_webauthn_registration(state.clone()))
}
pub fn landing(state: models::AppState) -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone + '_ {
warp::path::end()
.and(warp::any().map(move || state.clone()))
.and_then(handlers::landing_page)
}
pub fn start_webauthn_registration(state: models::AppState) -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone + '_ {
warp::path!("account" / "register-init")
.and(warp::post())
.and(json_body())
.and(warp::any().map(move || state.clone()))
.and_then(handlers::start_webauthn_registration)
}
fn json_body() -> impl Filter<Extract = (models::User,), Error = warp::Rejection> + Clone {
// When accepting a body, we want a JSON body
// (and to reject huge payloads)...
warp::body::content_length_limit(1024 * 16).and(warp::body::json())
}