From 8f53c9f718e6be24075427a95e42e6e17ca441f6 Mon Sep 17 00:00:00 2001 From: Radical Date: Thu, 17 Jul 2025 21:34:35 +0200 Subject: [PATCH] fix: try to fix up cors Login still not working, unsure of where failure point is --- src/main.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 15bae09..9624d18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use error::Error; use objects::MailClient; use socketioxide::SocketIo; use std::{sync::Arc, time::SystemTime}; -use tower_http::cors::{Any, CorsLayer}; +use tower_http::cors::{AllowHeaders, AllowMethods, AllowOrigin, CorsLayer}; mod config; use config::{Config, ConfigBuilder}; use diesel_migrations::{EmbeddedMigrations, MigrationHarness, embed_migrations}; @@ -128,11 +128,21 @@ async fn main() -> Result<(), Error> { let cors = CorsLayer::new() // Allow any origin (equivalent to allowed_origin_fn returning true) - .allow_origin(Any) + .allow_origin(AllowOrigin::predicate(|_origin, _request_head| { + true + })) // Allow any method - .allow_methods(Any) + .allow_methods(AllowMethods::mirror_request()) // Allow any headers - .allow_headers(Any); + .allow_headers(AllowHeaders::mirror_request()) + /* + vec![ + "content-type".parse().unwrap(), + "authorization".parse().unwrap(), + ] + */ + // Allow credentials + .allow_credentials(true); let (socket_io, io) = SocketIo::builder().with_state(app_state.clone()).build_layer();