corsjavaliteactiveweb

Activeweb CORS Option Preflight in Restful Controllers


When trying to connect to a restful controller in activeweb from a nodejs application chrome is sending options preflight request for delete and put methods, the preflight request needs to be handled by emitting a 200 response from the server.

As OPTIONS is not handled in restful controllers, I tried add below code to RouteConfig

boolean isMethodOptions = RequestUtils.isMethod("OPTIONS");
if (isMethodOptions) {
    route("/*").to(HomeController.class).action("optionResponse");
}

In HomeController

public void optionResponse(){
    respond("").status(200);
}

This doesn't work. How can this be done within the activeweb application?


Solution

  • This feature needs to be added to the framework. See this issue: https://github.com/javalite/activeweb/issues/306 Please, add your comments to it to kick-start implementation.