Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework: How to Get the Hostname Where the Application in Running

I know RequestHeader provides the host property that returns the hostname where application is running... but I need this info in my business code. Is there a way to determine the hostname without a RequestHeader?

like image 707
j3d Avatar asked Dec 15 '22 21:12

j3d


2 Answers

There are only two possible solutions to this problem. The first one you've already mentioned which is a RequestHeader. The second one is placing your hostname in the application.conf file.

like image 132
Daniel Olszewski Avatar answered May 11 '23 00:05

Daniel Olszewski


You can call InetAddress.getLocalHost().getHostName() to do a reverse lookup on the local host address.

Keep in mind that using the RequestHeader may be your only option, if the application is proxied in any way and virtual host support is expected.

like image 39
Szymon Jednac Avatar answered May 11 '23 00:05

Szymon Jednac