From 49c40b3bc38dd5a4d020c349a1fbd4c7b2f31a98 Mon Sep 17 00:00:00 2001 From: syeopite Date: Sun, 10 Nov 2024 00:47:39 -0800 Subject: [PATCH] Ensure before_all handler is called first --- src/invidious.cr | 6 +++--- src/invidious/helpers/handlers.cr | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) 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"