Skip to content

Commit

Permalink
API: Add APIHandler back (#4431)
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
SamantazFox committed Feb 18, 2024
2 parents 962ce23 + 7b84bdb commit e8a3698
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/invidious.cr
Expand Up @@ -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))
Expand Down
13 changes: 13 additions & 0 deletions src/invidious/helpers/handlers.cr
Expand Up @@ -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/*"]

Expand Down

0 comments on commit e8a3698

Please sign in to comment.