axum rewrite #35

Merged
radical merged 21 commits from staging into main 2025-07-20 17:25:04 +00:00
4 changed files with 16 additions and 21 deletions
Showing only changes of commit 8ec1610b2e - Show all commits

View file

@ -38,10 +38,10 @@ bindet = "0.3.2"
bunny-api-tokio = { version = "0.4", features = ["edge_storage"], default-features = false }
# Web Server
axum = { version = "0.8.4", features = ["macros", "multipart", "ws"] }
axum = { version = "0.8.4", features = ["multipart", "ws"] }
tower-http = { version = "0.6.6", features = ["cors"] }
axum-extra = { version = "0.10.1", features = ["cookie", "typed-header"] }
socketioxide = { version = "0.17.2", features = ["state"] }
#socketioxide = { version = "0.17.2", features = ["state"] }
url = { version = "2.5", features = ["serde"] }
time = "0.3.41"

View file

@ -24,7 +24,6 @@ pub struct RevokeRequest {
}
// TODO: Should maybe be a delete request?
#[axum::debug_handler]
pub async fn post(
State(app_state): State<Arc<AppState>>,
Extension(CurrentUser(uuid)): Extension<CurrentUser<Uuid>>,

View file

@ -1,20 +1,23 @@
use std::sync::Arc;
use axum::{
Router,
routing::{any, delete, get, patch},
middleware::from_fn_with_state, routing::{any, delete, get, patch}, Router
};
//use socketioxide::SocketIo;
use crate::AppState;
use crate::{api::v1::auth::CurrentUser, AppState};
mod uuid;
pub fn router() -> Router<Arc<AppState>> {
Router::new()
pub fn router(app_state: Arc<AppState>) -> Router<Arc<AppState>> {
let router_with_auth = Router::new()
.route("/{uuid}", get(uuid::get))
.route("/{uuid}", delete(uuid::delete))
.route("/{uuid}", patch(uuid::patch))
.route("/{uuid}/socket", any(uuid::socket::ws))
.route("/{uuid}/messages", get(uuid::messages::get))
.layer(from_fn_with_state(app_state, CurrentUser::check_auth_layer));
Router::new()
.route("/{uuid}/socket", any(uuid::socket::ws))
.merge(router_with_auth)
}

View file

@ -10,7 +10,6 @@ use diesel_async::pooled_connection::deadpool::Pool;
use diesel_migrations::{EmbeddedMigrations, MigrationHarness, embed_migrations};
use error::Error;
use objects::MailClient;
use socketioxide::SocketIo;
use std::{sync::Arc, time::SystemTime};
use tower_http::cors::{AllowOrigin, CorsLayer};
@ -24,7 +23,7 @@ mod config;
pub mod error;
pub mod objects;
pub mod schema;
mod socket;
//mod socket;
pub mod utils;
mod wordlist;
@ -53,12 +52,6 @@ pub struct AppState {
async fn main() -> Result<(), Error> {
tracing_subscriber::fmt::init();
//SimpleLogger::new()
// .with_level(log::LevelFilter::Info)
// .with_colors(true)
// .env()
// .init()
// .unwrap();
let args = Args::parse();
let config = ConfigBuilder::load(args.config).await?.build();
@ -158,12 +151,12 @@ async fn main() -> Result<(), Error> {
// Allow credentials
.allow_credentials(true);
let (socket_io, io) = SocketIo::builder()
/*let (socket_io, io) = SocketIo::builder()
.with_state(app_state.clone())
.build_layer();
io.ns("/", socket::on_connect);
*/
// build our application with a route
let app = Router::new()
// `GET /` goes to `root`
@ -172,8 +165,8 @@ async fn main() -> Result<(), Error> {
app_state.clone(),
))
.with_state(app_state)
.layer(cors)
.layer(socket_io);
//.layer(socket_io)
.layer(cors);
// run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind(web.ip + ":" + &web.port.to_string()).await?;