summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2024-02-13 21:05:26 +0100
committerSamantaz Fox <coding@samantaz.fr>2024-02-13 21:05:26 +0100
commit7b84bdb29b60504c1c5c88617e191767803384ab (patch)
tree41729c80798c5e36a04fe543a7da42757a5fc7a5 /src
parent5c0b6d8afab6412b906063c4a3341d470d17a506 (diff)
downloadinvidious-7b84bdb29b60504c1c5c88617e191767803384ab.tar.gz
invidious-7b84bdb29b60504c1c5c88617e191767803384ab.tar.bz2
invidious-7b84bdb29b60504c1c5c88617e191767803384ab.zip
API: Add APIHandler back
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/*"]