summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2024-02-19 00:05:34 +0100
committerSamantaz Fox <coding@samantaz.fr>2024-02-19 00:16:17 +0100
commite8a36985aff1a5b33ddf9abea85dd2c23422c2f7 (patch)
treefdead48413b37504d1a62cf22e8cb048aa53c388 /src
parent962ce23cc2ec4d1a5147b9b1e2c1d4d436365d28 (diff)
parent7b84bdb29b60504c1c5c88617e191767803384ab (diff)
downloadinvidious-e8a36985aff1a5b33ddf9abea85dd2c23422c2f7.tar.gz
invidious-e8a36985aff1a5b33ddf9abea85dd2c23422c2f7.tar.bz2
invidious-e8a36985aff1a5b33ddf9abea85dd2c23422c2f7.zip
API: Add APIHandler back (#4431)
This handler should no have been removed in 4276, as it adds the required CORS header (Access-Control-Allow-Origin) for public acces to the API. Thanks to iBicha for noticing this!
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr1
-rw-r--r--src/invidious/helpers/handlers.cr13
2 files changed, 14 insertions, 0 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index c8cac80e..e0bd0101 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -217,6 +217,7 @@ public_folder "assets"
Kemal.config.powered_by_header = false
add_handler FilteredCompressHandler.new
+add_handler APIHandler.new
add_handler AuthHandler.new
add_handler DenyFrame.new
add_context_storage_type(Array(String))
diff --git a/src/invidious/helpers/handlers.cr b/src/invidious/helpers/handlers.cr
index cece289b..174f620d 100644
--- a/src/invidious/helpers/handlers.cr
+++ b/src/invidious/helpers/handlers.cr
@@ -134,6 +134,19 @@ class AuthHandler < Kemal::Handler
end
end
+class APIHandler < Kemal::Handler
+ {% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %}
+ only ["/api/v1/*"], {{method}}
+ {% end %}
+ exclude ["/api/v1/auth/notifications"], "GET"
+ exclude ["/api/v1/auth/notifications"], "POST"
+
+ def call(env)
+ env.response.headers["Access-Control-Allow-Origin"] = "*" if only_match?(env)
+ call_next env
+ end
+end
+
class DenyFrame < Kemal::Handler
exclude ["/embed/*"]