Add CORS to API endpoints

このコミットが含まれているのは:
Omar Roth 2019-02-02 22:48:47 -06:00
コミット d0a690c303
2個のファイルの変更13行の追加0行の削除

ファイルの表示

@ -3977,6 +3977,7 @@ public_folder "assets"
Kemal.config.powered_by_header = false
add_handler FilteredCompressHandler.new
add_handler DenyFrame.new
add_handler APIHandler.new
add_context_storage_type(User)
Kemal.config.logger = logger

ファイルの表示

@ -43,6 +43,18 @@ class FilteredCompressHandler < Kemal::Handler
end
end
class APIHandler < Kemal::Handler
only ["/api/v1/*"]
def call(env)
return call_next env unless only_match? env
env.response.headers["Access-Control-Allow-Origin"] = "*"
call_next env
end
end
class DenyFrame < Kemal::Handler
exclude ["/embed/*"]