Split routes file, route prefix not being picked up

This is on 2.6.15, no other versions tested.

I created a split routes file in the conf/ folder, so now there is the classic routes and my.routes

In routes, the very first line reads:
-> /proj/my my.Routes

And my.routes just contains routes like

GET /files/ mypackage.controllers.my.MyController.getFiles()

The controller has been moved to the appropriate folder.

After compiling, I checked the RoutesPrefix.scala in target/scala-2.12/routes/main/my

It reads like this:

package my {
  object RoutesPrefix {
    private var _prefix: String = "/"
    def setPrefix(p: String): Unit = {
      _prefix = p
    def prefix: String = _prefix
    val byNamePrefix: Function0[String] = { () => prefix }

Which, apart from the package, is identical to the RoutesPrefix of main/router/

I would expect this line:

private var _prefix: String = "/"

to be

private var _prefix: String = "/proj/my"

As read from the routes file.

I tested it, it is generating routes without the correct prefix.

What am I doing wrong? Or is this a bug?

Hi @KoenDG,

Not bug exactly. Or are you seeing some unexpected behavior?

The prefix is applied defined when including my.routes and not by the sub-router itself. If you open the main generated router, you will see the prefix being applied at the include declaration (search for something like Include(myRoutes.withPrefix(...)).


I found that in target/scala-2.12/main/router/Routes.scala.

However, I’m using this file: target/scala-2.12/main/controllers/proj/my/routes.java for accessing the routes with the Reverse controllers.

And if I call those routes, the prefix isn’t included for the routes from my.Routes.

I’ll try and make a small demo app on github this weekend to demonstrate.

I’m encountering the same issue (Play 2.8.2). When using split routes sometimes (very seldom) the prefix is not picked up when running tests. Are the prefixes somehow lazy:ly injected after the test has already begun?

Did you @KoenDG resolve the issue or find a work-around? I guess hard coding the api endpoints as strings would work, but that’s kind of annoying when the route path should be available from the reverse routes.

Wow, this has been a while.

Haven’t worked with Play since changing jobs in 2018.

I recall I never ended up using this in production and the solution I came up with required the manual creation of a subdirectory with a specific name, per part of the url that was being split off.

Which was really cumbersome after a while and thus it ended up not happening.

There should be some kind of analysis that can be done in the compiled java files, in some target folder somewhere. It should have details somewhere of what it expects the path to be.

But that’s a real deep rabbithole you’re going down, if you choose to do so.

The behaviour of the router did change in 2.8.2 so the router gets lazily injected, and this may be why the prefix is missing when you run tests. Quite a frustrating issue to debug: