Play! 2.0 easy to fix OPTIONS answer for router?

Having some unpleasant problems causing AJAX calls, simply because almost every browser these days makes an OPTIONS call on the server before the actual AJAX call.

Since I use Play! 2.0, is there any easy way to make a response using a template for any route using the OPTIONS method?

For example, on my routes, you can do something like: OPTIONS /* controllers.Options.responseDef

Yes, I know the new Play! does not have a built-in template, but there must be a solution for this, since all browsers increasingly call OPTIONS before calling AJAX.

+1
source share
2 answers

, route, :

OPTIONS   /*wholepath     controllers.Options.responseDef(wholepath)
OPTIONS   /               controllers.Options.responseDef

:

OPTIONS    /a
OPTIONS    /a/b
OPTIONS    /a/b/c

: - , , , . .

, / .

+2

OPTIONS - onRouteRequest . onRouteRequest OptionsController.options.

import play.api.mvc._

...

override def onRouteRequest(request: RequestHeader): Option[Handler] = {
  request.method match {
    case "OPTIONS" => Some(OptionsController.options)
    case _ => super.onRouteRequest(request)
  }
}
+1

All Articles