Created
March 8, 2016 10:30
-
-
Save saeidzebardast/e375b7d17be3e0f4dddf 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", "*")); |
Thank you!!!
thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks it's working