Problem with GWT behind a reverse proxy - either nginx or apache

前端 未结 7 571
悲&欢浪女
悲&欢浪女 2020-12-15 22:20

I\'m having this problem with GWT when it\'s behind a reverse proxy. The backend app is deployed within a context - let\'s call it /context.

The GWT app works fine

7条回答
  •  不思量自难忘°
    2020-12-15 22:43

    KC's answer is good. For those that do not want to muck around with apache configs, or need a quick and dirty way to test, here is a code only solution.

    protected SerializationPolicy doGetSerializationPolicy(final HttpServletRequest request, String moduleBaseURL, final String strongName) {
        final String moduleBaseURLHdr = request.getHeader("X-GWT-Module-Base");
        if (moduleBaseURLHdr != null) {
            moduleBaseURL = moduleBaseURLHdr.replace("foo/bar", "bar");
        }
        return super.doGetSerializationPolicy(request, moduleBaseURL, strongName);
    }
    

    The application is on http://server/bar, the proxy is serving it at http://proxy/foo/bar Hence moduleBaseURL = moduleBaseURLHdr.replace("foo/bar", "bar"); makes GWT happy. Likewise if the application is at http://server/bar and the proxy is serving at http://proxy/, you need to add bar to the moduleBaseURL (right before the package name). This can be generalized through the use of getServletContext().getContextPath() etc...

提交回复
热议问题