1

I am not yet succeeding in making CORS requests work in my project, basically a Play server and an AngularJS web client.

Since there are many variables to take into consideration, I would like first to be sure that everything is ok at least on the Play server side. But, my fault, the Play 2.4 documentation on CORS is not enough to help me figure out a concrete use case.

Two basic questions:

  1. Creating a Filters class in the root of your project (see docs): where to place the provided code? Not sure what the "root of your project" is, I added the class to my controller in app/controllers/Mycontr.scala
  2. The points described in the documentation are enough? Or other parts need to be touched as well, for example routing in app/conf/routes

Tried to find a complete tutorial, but had no luck for Play 2.4

2 Answers 2

3

"root of your project" means a directory which corresponds to the package root. It is app/ by default, src/main/scala/ when using default sbt layout. That's all.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I placed the code in a newly created app/root.scala and now it works. So no other parts need to be touched server side in my case; and no need as well to change the AngularJS client side.
0

I am running into the same, issue, it keeps saying:

XMLHttpRequest cannot load http://localhost:9000/fetchBetween. Response to preflight request doesn't pass access control check: No 'Access-Control Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 404.

I added Filters.scala to my app/ folder, and added filters to libraryDependencies, this is my config in application.conf:

play.filters.cors {

  pathPrefixes = ["/fetchBetween"]

  allowedOrigins = ["*"]

  allowedHttpMethods = ["GET", "POST"]

  allowedHttpHeaders = ["Accept"]

  preflightMaxAge = 3 days

}

1 Comment

This spot is meant for answers, not questions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.