diff --git a/src/invidious.cr b/src/invidious.cr index e7654dcf..e9cfccd5 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -207,9 +207,9 @@ end # Routing -before_all do |env| - Invidious::Routes::BeforeAll.handle(env) -end +# Custom handlers actually has a higher priority than the handler defined via +# before_all +add_handler TrueBeforeAllHandler.new Invidious::Routing.register_all diff --git a/src/invidious/helpers/handlers.cr b/src/invidious/helpers/handlers.cr index f3e3b951..1e516694 100644 --- a/src/invidious/helpers/handlers.cr +++ b/src/invidious/helpers/handlers.cr @@ -60,6 +60,14 @@ class Kemal::ExceptionHandler end end +class TrueBeforeAllHandler < Kemal::Handler + def call(env) + return call_next(env) unless env.route_found? + Invidious::Routes::BeforeAll.handle(env) + call_next env + end +end + class FilteredCompressHandler < Kemal::Handler exclude ["/videoplayback", "/videoplayback/*", "/vi/*", "/sb/*", "/ggpht/*", "/api/v1/auth/notifications"] exclude ["/api/v1/auth/notifications", "/data_control"], "POST"