How do we make GWT accept dynamic domain name?

61 views
Skip to first unread message

Firesh Bakhda

unread,
Feb 10, 2021, 2:59:45 AM2/10/21
to GWT Users
Hi Team,

I am a new beginner, i was thinking how can GWT accept dynamic domain address/url via GWT since GWT requires compile, dont wanna be compiling everytime we move servers. 

Thomas Broyer

unread,
Feb 10, 2021, 6:21:47 AM2/10/21
to GWT Users
This means you somehow hard code the URL into your code. GWT itself doesn't do that, so it either come from your code or a third-party.
If it's coming from your code:
  • why do you do that? is the client code deployed to a different domain than the APIs it calls?
  • there are likely other ways of doing that (e.g. have the URL into the HTML host page, as a <meta>/<link> or a global variable in a <script>, and read it from your GWT app's onModuleLoad), but we'd need to know more about your problem first (see point above), and how you're currently addressing it (maybe you could show the portions of code where the URL is configured and then used?)

Ricardo Serathiuk

unread,
Feb 10, 2021, 6:23:46 AM2/10/21
to google-we...@googlegroups.com
You can try to create a hidden element on the HTML file with the server name. Example:

<input type="hidden" name="server-name" id="server-name" value="SERVER NAME HERE">

And you can get the value in GWT with:
InputElement input = (InputElement) Document.get().getElementById("server-name");
String serverName = input.getValue();

Another way is creating in the HTML file, a Javascript global variable via script tag or script file and load this via GWT using JSNI or JSInterop (the example is with JSNI):
<script>
window.SERVER_NAME = [SERVER_NAME_HERE];
</script>

In GWT:
public class ServerNameUtil {
public static native String getServerName() /*-{
   return $wnd.SERVER_NAME;
}-*/;
}

You can improve these ideas for your solution. IT is some ideas to help you to think of the best solution for your scenario. :)

Firesh Bakhda

unread,
Feb 10, 2021, 10:08:37 AM2/10/21
to google-we...@googlegroups.com
Ic.. so you are saying get the domain value via JavaScript and pass it to GWT, in that case anything that's written by user on the browser, becomes the domain name. 

Aha.. so in this case, basically GWT doesn't need to care what is the domain name. Hmm interesting. 

But in this case, this has to be at GWT EntryPoint? 

--
You received this message because you are subscribed to a topic in the Google Groups "GWT Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/Cumty5Oge1U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/CALVte5y6DcMON1BM4xpJ4FXWdSh-sEF5rG7Gtfavbjc9nwbBtg%40mail.gmail.com.

Firesh Bakhda

unread,
Feb 10, 2021, 10:15:07 AM2/10/21
to google-we...@googlegroups.com
One example I can give you on my issue is load balancing. 

Domain maybe abc.yyyy.com but the physical servers are def1.yyyy.com, def2.yyyy.com

2ndly, yes the api server maybe different from gwt, hence declaring hardcoded would cause a problem especially in fail over scenarios. 

So looking at avenue where I could flip a switch either from server end or from user end completely based on what url they are serving (may not solve the 2nd issue) 

--
You received this message because you are subscribed to a topic in the Google Groups "GWT Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/Cumty5Oge1U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.

Craig Mitchell

unread,
Feb 13, 2021, 6:40:47 AM2/13/21
to GWT Users
If you are using GWT RPC, then I think the RequestBuilder http://www.gwtproject.org/javadoc/latest/com/google/gwt/http/client/RequestBuilder.html can be customised to point to whatever URL you need.

However, your whole situation seems odd.  As Thomas mentioned, you'd normally serve up your client code from the same server you make calls too.  If you needed to switch servers with load balancing, you'd have a router, and that would redirect your traffic whereever you need.  All done outside the control of GWT.

Eg:  I run my GWT app on Google App Engine (GAE).  GAE has servers all around the world, but GAE handles the routing for me.  I don't need anything special in GWT.
Reply all
Reply to author
Forward
0 new messages