Skip to content

Instantly share code, notes, and snippets.

@toinetoine
Created August 13, 2018 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toinetoine/2f0b802184f519030164de81d8b897d9 to your computer and use it in GitHub Desktop.
Save toinetoine/2f0b802184f519030164de81d8b897d9 to your computer and use it in GitHub Desktop.
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