RealObjects Nimbudocs Editor 3.0.3929_Beta1

Guide: Reverse Proxy


Introduction

In most cases Nimbudocs Editor will be integrated into a governing web application. However, the server which serves the wep application is not necessarily the same server that hosts Nimbudocs Editor. This is a common scenario and has the following implications for the user: The browser will make requests from the web application site to the Nimbudocs Editor server. Since these are two different servers, the browser has to do cross-origin resource sharing (CORS) to access the Nimbudocs Editor server.

CORS

Cross-origin resource sharing is a means for the browser to request resources from another domain different from the current web site. If the user's browser supports CORS and allows for cross-origin XMLHttpRequests, this will work just fine since the Nimbudocs Editor server automatically sets appropriate headers to allow for CORS.

Reverse Proxy

CORS can only be used if the browser supports and allows it. Additionally, in some integration scenarios it may be desirable to control the connections made by the Nimbudocs Editor from the client to the Nimbudocs Editor server by tunneling all requests from the editor through the server of the integrating web application. This can be achieved by configuring a "reverse proxy".

Assuming your web application runs on the server webapp.mycompany.com and Nimbudocs Editor runs on another server nimbudocs.mycompany.com. If you want the clients not to make any requests to nimbudocs.mycompany.com directly, you can use a reverse proxy to tunnel all of the clients' requests through your web application server. So when setting up the reverse proxy you could configure it in a way that all requests made to webapp.mycompany.com/nimbudocs will be forwarded to nimbudocs.mycompany.com by the reverse proxy, eliminating the need for the clients to contact nimbudocs.mycompany.com directly.

The following examples show how to setup and configure a reverse proxy for different web application servers. The proxy is configred so that webapp.mycompany.com/nimbudocs will forward all requests to nimbudocs.mycompany.com.

Apache

The following web modules are required to enable reverse proxy functionality:

LoadModule proxy_module libexec/apache2/mod_proxy.so
LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so

And to setup the reverse proxy:

ProxyPass /nimbudocs http://nimbudocs.mycompany.com

IIS

The following modules must be installed on the IIS to set up a reverse proxy:

To configure a reverse proxy, you have to add a rewrite rule to the web.config of your web application like this:

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="nimbudocs/(.*)" />
                    <action type="Rewrite" url="http://nimbudocs.mycompany.com/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Jetty

When using Jetty you can write a simple reverse proxy servlet:

public class NimbudocsProxy extends ProxyServlet {
    public NimbudocsProxy() {
    }
    
    @Override
    protected HttpURI proxyHttpURI(HttpServletRequest request, String uri) {
        String servletContextPath = getServletConfig().getServletContext().getContextPath() + "/" + getServletConfig().getServletName();
        String nimbudocsServerUrl = "http://nimbudocs.mycompany.com";
        String requestUri = request.getRequestURI();
        String query = request.getQueryString();
        
        requestUri = requestUri.substring(servletContextPath.length());
        nimbudocsServerUrl += requestUri;
        
        if (query != null && query.length() > 0) {
            nimbudocsServerUrl += "?" + query;
        }
        
        HttpURI httpUri = new HttpURI(URI.create(nimbudocsServerUrl));
        
        return httpUri;
    }
}

To setup the servlet, you also have to add a few entries to your web.xml:

<servlet>
   <servlet-name>nimbudocs</servlet-name>
   <servlet-class>com.mycompany.NimbudocsProxy</servlet-class>
   <load-on-startup>1</load-on-startup>
   <async-supported>true</async-supported>
</servlet>

<servlet-mapping>
   <servlet-name>nimbudocs</servlet-name>
   <url-pattern>/nimbudocs</url-pattern>
   <url-pattern>/nimbudocs/*</url-pattern>
</servlet-mapping>

Usage

Once the reverse proxy has been configured and set up, you have to load the Nimbudocs Editor JavasScript files from the new URL as well as change the Nimbudocs Editor server URL appropriately.

Basic Integration:

<script src="http://nimbudocs.mycompany.com/nimbudocseditor.js"></script>
<script>
jQuery(window).load(function() {
    NimbudocsEditor.create("nimbuContainer", "http://nimbudocs.mycompany.com");
});
</script>

Integration With Reverse Proxy:

<script src="http://webapp.mycompany.com/nimbudocs/nimbudocseditor.js"></script>
<script>
jQuery(window).load(function() {
    NimbudocsEditor.create("nimbuContainer", "http://webapp.mycompany.com/nimbudocs");
});
</script>

As you can see, when using the reverse proxy, there are now only URLs used which contain the domain of your web application, namely webapp.mycompany.com instead of nimbudocs.mycompany.com.