This commit is contained in:
33
src/lib.rs
33
src/lib.rs
@@ -1,2 +1,33 @@
|
||||
pub mod handlers;
|
||||
pub mod models;
|
||||
pub mod models;
|
||||
|
||||
use axum::{routing::{get, post}, Router};
|
||||
use axum_sessions::{async_session::MemoryStore, SessionLayer};
|
||||
use oauth2::basic::BasicClient;
|
||||
use sqlx::SqlitePool;
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub pool: SqlitePool,
|
||||
pub oidc_client: BasicClient,
|
||||
}
|
||||
|
||||
pub fn create_app(state: AppState, session_secret: Vec<u8>) -> Router {
|
||||
let store = MemoryStore::new();
|
||||
let session_layer = SessionLayer::new(store, &session_secret).with_secure(false);
|
||||
|
||||
let app = Router::new()
|
||||
.route("/", get(handlers::index))
|
||||
.route("/auth/login", get(handlers::login))
|
||||
.route("/auth/callback", get(handlers::callback))
|
||||
.route("/input", post(handlers::input_post))
|
||||
.with_state(state)
|
||||
.layer(session_layer)
|
||||
.nest_service("/static", ServeDir::new("static"));
|
||||
|
||||
#[cfg(test)]
|
||||
let app = app.route("/test/login", get(handlers::test_login));
|
||||
|
||||
app
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user