diff options
| author | Omar Roth <omarroth@hotmail.com> | 2019-02-02 22:48:47 -0600 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2019-02-02 22:48:47 -0600 |
| commit | d0a690c30314d41661f706d66f868e6be56a0f66 (patch) | |
| tree | 4f7cd2226a5aa0ba7e1e6f3330aebb97d8f5f7e6 | |
| parent | 87e1fa0a28ea02ec3ab56d8d2b31990ff1fc22eb (diff) | |
| download | invidious-d0a690c30314d41661f706d66f868e6be56a0f66.tar.gz invidious-d0a690c30314d41661f706d66f868e6be56a0f66.tar.bz2 invidious-d0a690c30314d41661f706d66f868e6be56a0f66.zip | |
Add CORS to API endpoints
| -rw-r--r-- | src/invidious.cr | 1 | ||||
| -rw-r--r-- | src/invidious/helpers/helpers.cr | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index abdd8cb9..81318acf 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -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 diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 91a80203..942757c3 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -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/*"] |
