diff --git a/src/invidious.cr b/src/invidious.cr index abdd8cb99..81318acf6 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 91a802034..942757c32 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/*"]