Get the base URL of the Play app

I want to get the current base url of the application, usually http://localhost:9000/on localhost and http://mydomain.comon the server. If in the future I can start using https.

How can i do this?

+4
source share
3 answers

What version of Play Framework are you using?

If you use Play 1.x, you need to manually specify the base url of your application using the application.conf variable. So I do to get the base url for my applications. For example:

application.baseUrl=http://localhost:9000
%devcloud.application.baseUrl=http://dev-url.com
%prod.application.baseUrl=http://prod-url.com

Play Framework 2.x ( , - prod, dev, test...), : http://www.playframework.com/documentation/2.2.x/ProductionConfiguration

, . , URL-, .

+4

baseUrl: play.Play.application().configuration().getString("application.baseUrl")

+2

play.Play.application().configuration().getString("application.baseUrl"); . :

:

   @Inject
    Configuration configuration;

:

String baseUrl = configuration.getString("application.baseUrl");
0

Source: https://habr.com/ru/post/1523507/


All Articles