how to dynamically pass play.filters.hosts.allowed to a server

I am looking for a simple way of passing the play.filters.hosts.allowed parameter to a production play server started via a docker container.

Any advice on best practices to do this?

https://www.playframework.com/documentation/2.6.x/ProductionConfiguration shows how to override configuration parameters by using system properties and environment variables. But it is unclear how/whether this mechanism can be used for a list-valued configuration such as play.filter.hosts.allowed.

Is it necessary in this case to create a special prod.conf file or is there a simpler way to specify the production play.filters.hosts.allowed configuration?

Many thanks.

Azad

It should be possible to do -Dplay.filters.hosts.allowed.0=foo -Dplay.filters.hosts.allowed.1=bar. See https://github.com/lightbend/config/blob/61675293f7ed8e931abf81bcd0a982b0ae9020fd/HOCON.md#conversion-of-numerically-indexed-objects-to-arrays

2 Likes

Great. That worked.

Thank you so much for the tip.

Azad

Hi.
Apart from using these parameters, is it possible to change the allowed hosts entries programmatically with Scala/Java (e.g. based on entries in the database)?
All the best
jens

You can do it, but you’ll have to either create your own filter or bind your own instance of AllowedHostsConfig. It should be pretty straightforward though. Take a look at what the current code does and it should give you an idea: https://github.com/playframework/playframework/blob/master/web/play-filters-helpers/src/main/scala/play/filters/hosts/AllowedHostsFilter.scala#L27