Forked from saeidzebardast/Enable CORS in Spark Java
Created
February 20, 2019 14:49
-
-
Save rohmanhakim/73b93ff6467b04426bd7ae80b427d87d to your computer and use it in GitHub Desktop.
Enable CORS in Spark Java to allow origins *
This file contains hidden or 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", "*")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment