diff --git a/src/handlers/auth_handler.cr b/src/handlers/auth_handler.cr index 45e84a2..cb139e5 100644 --- a/src/handlers/auth_handler.cr +++ b/src/handlers/auth_handler.cr @@ -63,7 +63,10 @@ class AuthHandler < Kemal::Handler end def handle_auth(env) - return call_next(env) if request_path_startswith env, ["/login", "/logout"] + if request_path_startswith env, ["/login", "/logout"] || + requesting_static_file env + return call_next(env) + end unless validate_token env env.session.string "callback", env.request.path diff --git a/src/handlers/static_handler.cr b/src/handlers/static_handler.cr index 0287445..adaf3c1 100644 --- a/src/handlers/static_handler.cr +++ b/src/handlers/static_handler.cr @@ -16,10 +16,8 @@ class FS end class StaticHandler < Kemal::Handler - @dirs = ["/css", "/js", "/img", "/favicon.ico"] - def call(env) - if request_path_startswith env, @dirs + if requesting_static_file env file = FS.get? env.request.path return call_next env if file.nil? diff --git a/src/util.cr b/src/util.cr index 3397aeb..921f281 100644 --- a/src/util.cr +++ b/src/util.cr @@ -2,6 +2,11 @@ require "big" IMGS_PER_PAGE = 5 UPLOAD_URL_PREFIX = "/uploads" +STATIC_DIRS = ["/css", "/js", "/img", "/favicon.ico"] + +def requesting_static_file(env) + request_path_startswith env, STATIC_DIRS +end macro layout(name) base_url = Config.current.base_url