Created
September 16, 2019 14:46
-
-
Save jsmsalt/f58e3c43f1f615dc7f4bbd89f31d7020 to your computer and use it in GitHub Desktop.
Spark Java CORS Fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
options("/*", (request, response) -> { | |
String accessControlRequestHeaders = request.headers("Access-Control-Request-Headers"); | |
if (accessControlRequestHeaders != null) { | |
response.header("Access-Control-Allow-Headers", accessControlRequestHeaders); | |
} | |
String accessControlRequestMethod = request.headers("Access-Control-Request-Method"); | |
if (accessControlRequestMethod != null) { | |
response.header("Access-Control-Allow-Methods", accessControlRequestMethod); | |
} | |
return "OK"; | |
}); | |
before((request, response) -> response.header("Access-Control-Allow-Origin", "*")); | |
// Paths |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment