From 67b915d722bbe07cc11bd46249ff06df022c0a00 Mon Sep 17 00:00:00 2001 From: Imbus Date: Tue, 28 Nov 2023 04:20:00 +0100 Subject: [PATCH] Simple cors --- server/Cargo.lock | 16 ++++++++++++++++ server/Cargo.toml | 1 + server/src/main.rs | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/server/Cargo.lock b/server/Cargo.lock index bfc7374..7b87062 100755 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -19,6 +19,21 @@ dependencies = [ "tracing", ] +[[package]] +name = "actix-cors" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b340e9cfa5b08690aae90fb61beb44e9b06f44fe3d0f93781aaa58cfba86245e" +dependencies = [ + "actix-utils", + "actix-web", + "derive_more", + "futures-util", + "log", + "once_cell", + "smallvec", +] + [[package]] name = "actix-files" version = "0.6.2" @@ -1840,6 +1855,7 @@ dependencies = [ name = "server" version = "0.1.0" dependencies = [ + "actix-cors", "actix-files", "actix-web", "argon2", diff --git a/server/Cargo.toml b/server/Cargo.toml index d3046e3..70899a1 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +actix-cors = "0.6.4" actix-files = "0.6.2" actix-web = "4.4.0" argon2 = { version = "0.5.2", features = ["zeroize"] } diff --git a/server/src/main.rs b/server/src/main.rs index 06ed9ce..7979244 100755 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,3 +1,4 @@ +use actix_cors::Cors; use actix_files::Files; use actix_web::middleware; use actix_web::web::Data; @@ -34,7 +35,13 @@ async fn main() -> std::io::Result<()> { info!("Spinning up server on http://localhost:8080"); HttpServer::new(move || { + let cors = Cors::default() + .allowed_origin("https://shitpost.se") + .allowed_methods(vec!["GET", "POST"]) + .max_age(3600); + App::new() + .wrap(cors) .wrap(middleware::Compress::default()) .wrap(middleware::Logger::default()) .wrap(middleware::NormalizePath::trim())