aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-02-27 15:44:50 +0100
committermetamuffin <metamuffin@disroot.org>2026-02-27 15:44:52 +0100
commit70e6d510ba236730260371a3259ffb16f999f5d4 (patch)
tree8765baac9be7e88c24e13a6cecd2baac506ccb4f
parent7c1d5f757638e3941edf20dbf01a3c8d82d25d96 (diff)
downloadhurrycurry-70e6d510ba236730260371a3259ffb16f999f5d4.tar
hurrycurry-70e6d510ba236730260371a3259ffb16f999f5d4.tar.bz2
hurrycurry-70e6d510ba236730260371a3259ffb16f999f5d4.tar.zst
registry: implement OPTIONS for cors requests
-rw-r--r--server/registry/src/list.rs7
-rw-r--r--server/registry/src/main.rs4
2 files changed, 9 insertions, 2 deletions
diff --git a/server/registry/src/list.rs b/server/registry/src/list.rs
index 05c2eeab..56277db5 100644
--- a/server/registry/src/list.rs
+++ b/server/registry/src/list.rs
@@ -21,6 +21,7 @@ use hurrycurry_protocol::registry::Entry;
use rocket::{
Either, Request, State, get,
http::{Header, MediaType},
+ options,
request::{self, FromRequest, Outcome},
response::{
self, Responder,
@@ -44,6 +45,11 @@ pub(super) async fn r_list(
})
}
+#[options("/v1/list")]
+pub(super) async fn r_list_options() -> Cors<()> {
+ Cors(())
+}
+
pub(super) fn generate_json_list(entries: &[Entry]) -> Result<Arc<str>> {
Ok(serde_json::to_string(&entries)?.into())
}
@@ -122,6 +128,7 @@ impl<'r, T: Responder<'r, 'static>> Responder<'r, 'static> for Cors<T> {
fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> {
let mut b = self.0.respond_to(req)?;
b.set_header(Header::new("access-control-allow-origin", "*"));
+ b.set_header(Header::new("access-control-allow-methods", "GET, OPTIONS"));
Ok(b)
}
}
diff --git a/server/registry/src/main.rs b/server/registry/src/main.rs
index 3cd252d9..924cbe24 100644
--- a/server/registry/src/main.rs
+++ b/server/registry/src/main.rs
@@ -21,7 +21,7 @@ pub mod list;
pub mod lobby;
pub mod register;
-use crate::conn_test::prune_connect_cache_task;
+use crate::{conn_test::prune_connect_cache_task, list::r_list_options};
use hurrycurry_protocol::registry::Entry;
use list::{generate_html_list, generate_json_list, r_list};
use lobby::lobby_wrapper;
@@ -78,7 +78,7 @@ fn main() {
res.set_header(Header::new("server", "hurrycurry-registry"));
Box::pin(async {})
}))
- .mount("/", routes![r_index, r_list, r_register])
+ .mount("/", routes![r_index, r_list, r_list_options, r_register])
.ignite()
.await
.unwrap()