Is it possible to have the following routing in dev mode:
GET / controllers.Assets.at(path="/public/ui/dev", file="index.html")
GET /*file controllers.Assets.at(path="/public/ui/dev", file)
and the following in production:
GET / controllers.Assets.at(path="/public/ui/prod", file="index.html")
Yes it is possible. Declare your dev routes in conf/routes
, but declare your production routes in conf/prod.routes
. Then, have a production configuration file, conf/prod.conf
, and put this in it:
include "application.conf"
application.router = "prod.Routes"
Now, when you start your application in production, simply use:
path/to/myapp/bin/myapp -Dconfig.resource=prod.conf -Dhttp.port=...
The solution above works well but means you are duplicating routes for e.g. non-static resources in your routes
and prod.routes
files.
If you want to keep a single routes file, you can go down the road that johanandren proposes. I use this method quite successfully, and have posted a gist for this method at https://gist.github.com/drcharris/2e3518b212adfa1b6a7f
Not out of the box. But here you have two ideas of how you might achieve the same functionality:
- write a thin wrapper around Assets.at that looks at the current env and handles it differently, and then just calling Assets.at with the modified path
- override how routing is done in Global, this is a bit hard to do if you want to keep using the routes DSL for both prod and dev routes file as you would have to figure out to get them compiled