How to automatically append gwt.codesvr to page UR

2019-05-14 07:36发布

问题:

When running a GWT application in hosted mode one usually needs to add the location of the code server in a query string parameter, for example instead of index.html one may need to open index.html?gwt.codesvr=127.0.0.1:9997. The problem is that gwt.codesvr is not usually included in hyperlinks, so it has to be added manually. Adding it to all links in your application does not seem a good idea as it will interfere with the final GWT-compiled version. Another option is for index.html to introspect itself by JavaScript and append a default gwt.codesvr to window.location, but this should be done only after the application is sure that it has not been compiled, that is after the GWT module may need to be (re)compiled alert. The ideal solution, I believe, would be for GWT to allow customization of the action it does after it finds no permutations to select from. The default action is to show the alert warning just mentioned, but unfortunately this is not customizable.

So my question is this: what is the best way to automatically open the current page with a default gwt.codesvr when there is no compiled permutations.

回答1:

Since I'm dealing with 'Places' all the time now I updated the bookmarklet to deal with '#' too.

javascript:(function(){h="localhost";p="9997";l="gwt.codesvr="+h+":"+p;s=false;if(document.location.href.indexOf("gwt.codesvr")<0){q=document.location.href.indexOf("?");if(q<0){q=document.location.href.indexOf("#");if(q>0){q=q-1}s=true}if(q<0&&!s){document.location.href=document.location.href+"?"+l}else%20if(q>=0&&!s){b=document.location.href.substr(0,q+1);e=document.location.href.substr(q+1);document.location.href=b+l+"&"+e}else{b=document.location.href.substr(0,q+1);if(q<0){e=""}else{e=document.location.href.substr(q+1)}document.location.href=b+"?"+l+e}}})();

Update 2/7/2017- There had been a typo in the script. Corrected it.



回答2:

I made a bookmarklet that I click to debug the current page:

javascript:window.location+=(window.location.href.indexOf('?')==-1?"?":"&")+"gwt.codesvr=localhost:9997"

but that doesn't account for the hash at the end, which you may not need anyway. That bookmarklet is about the only thing I use my bookmarks bar for...

Possibly worth pointing out that this can be used even with a production server, as long as you have roughly the same client code locally that that server was running.



回答3:

Since you'll be using that url only for development (and maybe few times for remote debugging), just bookmark http://127.0.0.1:8888/index.html?gwt.codesvr=127.0.0.1:9997 (or whatever port you use).