如何获取 appengine 应用的当前服务器 URL? [英] How to get the current server URL of appengine app?
问题描述
我正在尝试从代码中获取当前正在运行的 appengine java 应用程序的服务器 URL.也就是说,如果该应用程序在我的本地开发机器上运行,我希望以某种方式返回 "http://localhost:8080" 但如果它在 prod 中运行,我希望得到返回 "http://myappid.appspot.com".是否有任何 java 或 appengine API 可以做到这一点?我不想手动更改和读取配置文件或常量.
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.
谢谢.
- 阿莱姆
推荐答案
你应该可以使用 getServerName():
You should be able to use getServerName():
boolean local = "localhost".equals(httpServletRequest.getServerName());
如果您需要更多信息,还可以使用其他方法,例如getServerPort().
There are other methods you can also use if you need more info, e.g. getServerPort().
这篇关于如何获取 appengine 应用的当前服务器 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!