summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/invidious.cr1
-rw-r--r--src/invidious/helpers/helpers.cr12
2 files changed, 13 insertions, 0 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index abdd8cb9..81318acf 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -3977,6 +3977,7 @@ public_folder "assets"
Kemal.config.powered_by_header = false
add_handler FilteredCompressHandler.new
add_handler DenyFrame.new
+add_handler APIHandler.new
add_context_storage_type(User)
Kemal.config.logger = logger
diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr
index 91a80203..942757c3 100644
--- a/src/invidious/helpers/helpers.cr
+++ b/src/invidious/helpers/helpers.cr
@@ -43,6 +43,18 @@ class FilteredCompressHandler < Kemal::Handler
end
end
+class APIHandler < Kemal::Handler
+ only ["/api/v1/*"]
+
+ def call(env)
+ return call_next env unless only_match? env
+
+ env.response.headers["Access-Control-Allow-Origin"] = "*"
+
+ call_next env
+ end
+end
+
class DenyFrame < Kemal::Handler
exclude ["/embed/*"]