From f66df8716858169e99d61bb2b8eb35fe475c7ec1 Mon Sep 17 00:00:00 2001 From: AINDUSTRIES Date: Sun, 16 Mar 2025 23:39:21 +0100 Subject: [PATCH] Added options route for every route for client cors --- src/utils.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/utils.rs diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..1c26a23 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,12 @@ +use actix_web::{options, HttpResponse, Responder}; + +// This is needed for the web client. +// This returns the same options for every path of the api +#[options("/{_:.*}")] +async fn options() -> impl Responder { + HttpResponse::Ok() + .append_header(("Access-Control-Allow-Origin", "*")) + .append_header(("Access-Control-Allow-Methods", "GET, OPTIONS")) + .append_header(("Access-Control-Allow-Headers", "Content-Type")) + .finish() +}