In Play Framework, I’ve noticed that it’s possible to separate configuration properties that are used in Dev or Prod mode.
The best in-use example is for baseUrl :
# Url-resolving in Jobs
# ~~~~~~
# When rendering templates with reverse-url-resoling (@@{..}) in Jobs (which do not have an inbound Http.Request),
# ie if sending a HtmlMail, Play need to know which url your users use when accessing your app.
# %test.application.baseUrl=http://localhost:9000/
%dev.application.baseUrl=http://127.0.0.1:9000
%prod.application.baseUrl=http://www.example.com
But I can’t make it work for another property:
%dev.application.staticUrl=/public
%prod.application.staticUrl=http://static.example.com
Calling Play.configuration.getProperty("application.staticUrl"), or even Play.configuration.getProperty("%dev.application.staticUrl") (to test) doesn’t make it :/
How can I make this work?
When running in dev mode you do not need to prefix your line with dev.
I run my app in dev mode when developing the app and prod mode with 2 instances.
Sample of my application.conf:
Running the app with play run myapp will use the properties without prefix.
In prod mode I run 2 instances with play start --%inst1 and play start --%inst2.
This will create 2 instances of the app running with their own properties or the default one if not specified.
When you use getProperty, never use the prefix i.e. Play.configuration.getProperty("mail.smtp") will return mock in dev mode or MAILSERVER1 in prod mode.
In your case you have two configurations (not to be mistaken with running mode!), dev and prod. The application running mode is defined by application.mode property.