diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-07-17 23:42:55 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-07-17 23:44:11 +0200 |
| commit | bef3da2a567e3804e12355d9c3d5c09439dbe2ea (patch) | |
| tree | ab7974c941bd31994da46150234976b33c2f61b5 /server | |
| parent | 145be2b3c92e254904d4040850e3c1e9b6a66f32 (diff) | |
Humble beginnings
Redirect to login if not logged in, on login session cookie is set
and projects or reviews are listed.
Diffstat (limited to 'server')
| -rw-r--r-- | server/Cargo.lock | 28 | ||||
| -rw-r--r-- | server/Cargo.toml | 1 | ||||
| -rw-r--r-- | server/src/auth.rs | 2 | ||||
| -rw-r--r-- | server/src/main.rs | 11 |
4 files changed, 41 insertions, 1 deletions
diff --git a/server/Cargo.lock b/server/Cargo.lock index cf2a209..52168cd 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -593,6 +593,7 @@ dependencies = [ "reqwest", "rmp-serde", "rocket", + "rocket_cors", "rocket_db_pools", "serde", "serial_test", @@ -2133,6 +2134,23 @@ dependencies = [ ] [[package]] +name = "rocket_cors" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfac3a1df83f8d4fc96aa41dba3b86c786417b7fc0f52ec76295df2ba781aa69" +dependencies = [ + "http 0.2.12", + "log", + "regex", + "rocket", + "serde", + "serde_derive", + "unicase", + "unicase_serde", + "url", +] + +[[package]] name = "rocket_db_pools" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3262,6 +3280,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" [[package]] +name = "unicase_serde" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ef53697679d874d69f3160af80bc28de12730a985d57bdf2b47456ccb8b11f1" +dependencies = [ + "serde", + "unicase", +] + +[[package]] name = "unicode-bidi" version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/server/Cargo.toml b/server/Cargo.toml index 9cf031f..a634083 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -30,6 +30,7 @@ log.workspace = true pretty_assertions.workspace = true rmp-serde.workspace = true rocket = { version = "0.5.1", features = ["json", "secrets"] } +rocket_cors = "0.6.0" rocket_db_pools = { version = "0.2.0", features = ["sqlx_mysql"] } serde.workspace = true serial_test = "3.2.0" diff --git a/server/src/auth.rs b/server/src/auth.rs index edd794c..530b2ef 100644 --- a/server/src/auth.rs +++ b/server/src/auth.rs @@ -225,7 +225,7 @@ async fn login( ); let cookie = Cookie::build((SESSION_COOKIE, json::to_string(&session).unwrap())) - .path("/api") + .path("/") .max_age(max_age) .http_only(true) .build(); diff --git a/server/src/main.rs b/server/src/main.rs index 7a6b1b7..9a4f781 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -8,6 +8,7 @@ use rocket::http::Status; use rocket::response::status::{Custom, NotFound}; use rocket::serde::json::Json; use rocket::{futures, Build, Rocket, State}; +use rocket_cors::AllowedOrigins; use rocket_db_pools::{sqlx, Connection, Database}; use sqlx::Acquire; use std::path::PathBuf; @@ -1465,6 +1466,15 @@ async fn run_migrations(rocket: Rocket<Build>) -> fairing::Result { fn rocket_from_config(figment: Figment) -> Rocket<Build> { let basepath = "/api/v1"; + + let cors = rocket_cors::CorsOptions { + allowed_origins: AllowedOrigins::all(), + allow_credentials: false, + ..Default::default() + } + .to_cors() + .unwrap(); + rocket::custom(figment) .attach(Db::init()) .attach(AdHoc::try_on_ignite("Database Migrations", run_migrations)) @@ -1497,6 +1507,7 @@ fn rocket_from_config(figment: Figment) -> Rocket<Build> { translation_reviews, ], ) + .attach(cors) .attach(auth::stage(basepath)) .attach(git_root::stage()) .attach(authorized_keys::stage()) |
