AscendingCreations/AxumSession

Exclude session creation for certain routes

j0lol opened this issue · 1 comments

I have certain routes that do not need to be linked to a session (one off webhooks), i would like to exclude them to not wastefully add rows to my database. How would I do this, if possible?

Routes that need to be excluded from the system you would need to place them After the layer. Anytime you place stuff after the layers in the Router creation it makes it so those Routes don't have any layer other than those added after them.

for example i do mine like

 let app = Router::new()
        .route("/", get(root))
        .merge(main_routes())
        .merge(user_routes())
        .merge(view_routes())
        .merge(admin_routes())
        .merge(generator_routes())
        .fallback(site::handler_404)
        .layer(CatchPanicLayer::new())
        .layer(SetSensitiveHeadersLayer::new(once(header::AUTHORIZATION)))
        .layer(TraceLayer::new_for_http())
        .route("/reports/progress", post(progress_post))
        .layer(CompressionLayer::new())
        .layer(Extension(poll.clone()))
        .layer(middleware::from_fn(online_updater))
        .layer(Extension(server_state))
        .layer(
            AuthSessionLayer::<User, i64, SessionPgPool, PgPool>::new(Some(poll))
                .with_config(auth_config),
        )
        .layer(SessionLayer::new(session_store))
        .layer(CorsLayer::new().allow_origin(Any).allow_methods(Any))
        .nest_service("/static", get_service(ServeDir::new("static")))
        .with_state(system_state.clone());
        ```