Created
August 13, 2018 14:28
-
-
Save toinetoine/2f0b802184f519030164de81d8b897d9 to your computer and use it in GitHub Desktop.
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
private static final HashMap<String, String> corsHeaders = new HashMap<String, String>(); | |
static { | |
corsHeaders.put("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS"); | |
corsHeaders.put("Access-Control-Allow-Origin", "*"); | |
corsHeaders.put("Access-Control-Allow-Headers", "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin,"); | |
corsHeaders.put("Access-Control-Allow-Credentials", "true"); | |
} | |
public final static void apply() { | |
Filter filter = new Filter() { | |
@Override | |
public void handle(Request request, Response response) throws Exception { | |
corsHeaders.forEach((key, value) -> { | |
response.header(key, value); | |
}); | |
} | |
}; | |
Spark.after(filter); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment