summaryrefslogtreecommitdiff
path: root/src/cors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cors.rs')
-rw-r--r--src/cors.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/cors.rs b/src/cors.rs
new file mode 100644
index 0000000..700e4bb
--- /dev/null
+++ b/src/cors.rs
@@ -0,0 +1,25 @@
+use rocket::fairing::{Fairing, Info, Kind};
+use rocket::http::Header;
+use rocket::{Request, Response};
+
+pub struct CORS;
+
+#[rocket::async_trait]
+impl Fairing for CORS {
+ fn info(&self) -> Info {
+ Info {
+ name: "Add CORS headers to responses",
+ kind: Kind::Response,
+ }
+ }
+
+ async fn on_response<'r>(&self, _req: &'r Request<'_>, response: &mut Response<'r>) {
+ response.set_header(Header::new("Access-Control-Allow-Origin", "*"));
+ response.set_header(Header::new(
+ "Access-Control-Allow-Methods",
+ "POST, GET, PATCH, OPTIONS",
+ ));
+ response.set_header(Header::new("Access-Control-Allow-Headers", "*"));
+ response.set_header(Header::new("Access-Control-Allow-Credentials", "true"));
+ }
+}