简体   繁体   English

如何自动将gwt.codesvr附加到页面URL

[英]How to automatically append gwt.codesvr to page URL

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 . 通常在托管模式下运行GWT应用程序时,通常需要在查询字符串参数中添加代码服务器的位置,例如,而不是index.html可能需要打开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. 问题是gwt.codesvr通常不包含在超链接中,因此必须手动添加。 Adding it to all links in your application does not seem a good idea as it will interfere with the final GWT-compiled version. 将它添加到应用程序中的所有链接似乎不是一个好主意,因为它会干扰最终的GWT编译版本。 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. 另一个选择是让index.html通过JavaScript内省自己并将一个默认的gwt.codesvr附加到window.location ,但这只应在应用程序确定它尚未编译之后,即在GWT module may need to be (re)compiled之后GWT module may need to be (re)compiled警报。 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. 我相信,理想的解决方案是让GWT在找不到可供选择的排列后,自定义它所执行的操作。 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. 所以我的问题是:当没有编译的排列时,用默认的gwt.codesvr自动打开当前页面的最佳方法是什么。

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. 可能值得指出的是,即使在生产服务器上也可以使用它,只要您在本地具有与该服务器运行的大致相同的客户端代码即可。

Since I'm dealing with 'Places' all the time now I updated the bookmarklet to deal with '#' too. 由于我现在一直在处理'Places',所以我更新了书签以处理'#'。

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. 2017年2月7日更新 -剧本中出现了拼写错误。 Corrected it. 纠正了它。

由于您将仅使用该URL进行开发(可能只有几次用于远程调试),只需将书签http://127.0.0.1:8888/index.html?gwt.codesvr=127.0.0.1:9997 (或任何端口)你用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM