Skip to content

Instantly share code, notes, and snippets.

@danielreuterwall
Created January 9, 2015 22:07
Show Gist options
  • Save danielreuterwall/46cda78f9075c1476d8f to your computer and use it in GitHub Desktop.
Save danielreuterwall/46cda78f9075c1476d8f to your computer and use it in GitHub Desktop.
public static class CorsAction extends Action.Simple {
public Result call(Context context) throws Throwable{
Response response = context.response();
response.setHeader("Access-Control-Allow-Origin", *);
//Handle preflight requests
if(context.request().method().equals("OPTIONS")) {
response.setHeader("Access-Control-Allow-Methods", "POST");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
return ok();
}
response.setHeader("Access-Control-Allow-Headers","X-Requested-With");
return delegate.call(context);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment