Jay Prall
Jay Prall

Reputation: 5465

How to get grails 3.x to respond to an OPTIONS request?

In grails 2.x, we had to add this to the src/templates/war/web.xml in order for it to route an OPTIONS request. These types of requests are used when CORS is used.

<servlet>
    <servlet-name>grails</servlet-name>
    <servlet-class>org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <init-param>
        <param-name>dispatchOptionsRequest</param-name>
        <param-value>true</param-value>
    </init-param>
</servlet>

web.xml isn't used anymore in grails 3 so there must be a new way. I'm also curious why this option doesn't default on.

Upvotes: 0

Views: 217

Answers (1)

Jay Prall
Jay Prall

Reputation: 5465

It appears the new way to configure is in resources.groovy:

import org.grails.web.servlet.mvc.GrailsDispatcherServlet

beans = {
    // configure dispatch servlet so it dispatches OPTIONS requests
    dispatcherServlet(GrailsDispatcherServlet) {
        dispatchOptionsRequest = true
    }
}

Upvotes: 1

Related Questions