31 lines
1015 B
Rust
31 lines
1015 B
Rust
use crate::diesel::PgConnection;
|
|
use crate::logging::LogService;
|
|
use async_redis_session::RedisSessionStore;
|
|
use axum::{prelude::*, routing::BoxRoute, AddExtensionLayer};
|
|
use diesel::r2d2::{ConnectionManager, Pool};
|
|
use std::env;
|
|
|
|
pub mod block;
|
|
pub mod discord;
|
|
pub mod user;
|
|
|
|
// this should never get called, because the reverse
|
|
// proxy on caddy should only direct calls from /api
|
|
async fn root() -> &'static str {
|
|
"Hi"
|
|
}
|
|
|
|
pub fn get_routes(pool: Pool<ConnectionManager<PgConnection>>) -> BoxRoute<Body> {
|
|
let redis_url = env::var("REDIS_URL").unwrap_or(String::from("redis://localhost"));
|
|
|
|
let client = redis::Client::open(redis_url.as_str()).expect("Could not create redis client.");
|
|
route("/", get(root))
|
|
.nest("/discord", discord::get_routes())
|
|
.layer(tower::layer::layer_fn(|service| LogService { service }))
|
|
.layer(AddExtensionLayer::new(RedisSessionStore::from_client(
|
|
client,
|
|
)))
|
|
.layer(AddExtensionLayer::new(pool))
|
|
.boxed()
|
|
}
|