I'm trying to get the server URL of a currently running appengine java app from code. That is, if the app is running on my local dev machine I would like to somehow get returned "http://localhost:8080" but if it is running in prod I'd like to be returned "http://myappid.appspot.com". Are there any java or appengine API's that can do this? I'd like to not have a to manually change and read from a config file or a constant.
Thanks.
This is working for me in Java on appengine:
String hostUrl;
String environment = System.getProperty("com.google.appengine.runtime.environment");
if (StringUtils.equals("Production", environment)) {
String applicationId = System.getProperty("com.google.appengine.application.id");
String version = System.getProperty("com.google.appengine.application.version");
hostUrl = "http://"+version+"."+applicationId+".appspot.com/";
} else {
hostUrl = "http://localhost:8888";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With