summaryrefslogtreecommitdiff
path: root/src/vapid/middleware.rs
blob: 02951ba17da96afbd771dab0d2fe3acadc222dc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use axum::{
    extract::{Request, State},
    middleware::Next,
    response::Response,
};

use crate::{app::App, clock::RequestedAt, error::Internal};

pub async fn middleware(
    State(app): State<App>,
    RequestedAt(now): RequestedAt,
    request: Request,
    next: Next,
) -> Result<Response, Internal> {
    app.vapid().refresh_key(&now).await?;
    Ok(next.run(request).await)
}