Define CORS in Lagom framework

java
play-1

(Yaniv) #1

Hi,

I’m currently developing client(ReactJs) server(Java) web application.
I’m trying to configure my back-end to work with method type ‘OPTIONS’ with no success.
How can it be done?

Thanks,
Yaniv.


(Michael Liarakos) #2

Have you taken a look at the Lagom recipe for CORS? It has both Java and Scala examples.


(Yaniv) #3

Hi,
Thanks for the quick response.

yes, I saw the example.
The ‘Options’ request defined in a specific service impl, but lagom’s gateway blocks the request before it reaches the service api.


(Michael Liarakos) #4

Try two things:

  • Test a CORS HTTP request directly to the service rather than the gateway. Lagom should display the port assigned to the service when you start dev mode.
  • Call withAutoAcl(true) in the service api and see it that enables you to make CORS requests through the gateway.

(Yaniv) #5

Hi,

I found the problem, in the application.conf I changed pathPrefixes = ["/api"] to pathPrefixes = ["/"] and
in my service impl I added withServiceAcls(
ServiceAcl.methodAndPath(Method.OPTIONS, “/.*”)
with general path prefix and now it works.

Thank you,
Yaniv.