about summary refs log tree commit diff
path: root/src/micropub
diff options
context:
space:
mode:
Diffstat (limited to 'src/micropub')
-rw-r--r--src/micropub/mod.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/micropub/mod.rs b/src/micropub/mod.rs
index 68a3134..84b9083 100644
--- a/src/micropub/mod.rs
+++ b/src/micropub/mod.rs
@@ -4,3 +4,24 @@ pub mod post;
 pub use get::get_handler;
 pub use post::normalize_mf2;
 pub use post::post_handler;
+
+pub struct CORSMiddleware {}
+
+use async_trait::async_trait;
+use tide::{Next, Request, Result};
+use crate::database;
+use crate::ApplicationState;
+
+#[async_trait]
+impl<B> tide::Middleware<ApplicationState<B>> for CORSMiddleware
+where
+    B: database::Storage + Send + Sync + Clone,
+{
+    async fn handle(&self, req: Request<ApplicationState<B>>, next: Next<'_, ApplicationState<B>>) -> Result {
+        let mut res = next.run(req).await;
+
+        res.insert_header("Access-Control-Allow-Origin", "*");
+
+        Ok(res)
+    }
+}