RemoteViz uses WebSocket protocol to make possible the communication between the client and the service. Without any web servers between the client and the RemoteViz service, a WebSocket connection can be established smoothly. However, in production environments, the web page requests are handled by a web server and only the web server port (port 80 by default) is open from the outside in order to guarantee security. To use the same port and domain for the HTTP requests and the Websocket requests, the websocket traffic has to be routed through the web server. This document explains how to configure NodeJS server as reverse proxy to handle web page requests and websocket traffic over the same port and domain.
For Microsoft Windows and Unix systems: http://nodejs.org/download/
For Microsoft Windows and Unix systems: https://github.com/nodejitsu/node-http-proxy
The recommended installation method is via npm: npm install http-proxy
Without Secure Sockets Layer (SSL) encryption:
var http = require('http'), fs = require('fs'), httpProxy = require('http-proxy'); // This line refers to the node-http-proxy library. // Route websocket requests to the RemoteViz service // Replace "remoteviz_service_ip" by the RemoteViz service IP address var proxy = new httpProxy.createProxyServer({ target: { host: 'remoteviz_service_ip', port: 8080 ;} }); // Configure the HTTP server to respond to all requests. var proxyServer = http.createServer(function (req, res) { /* HERE, write your HTTP server logic. The following example returns the index.html page to the client. if (req.url == '/index.html'){ var page = fs.readFileSync(__dirname + '/index.html'); res.writeHead(200, {'Content-Type': 'text/html'}); res.write(page); res.end(); } */ }); // Listen to the `upgrade` event and proxy the WebSocket requests. proxyServer.on('upgrade', function (req, socket, head) { proxy.ws(req, socket, head); }); // Web server IP address and port; Replace "yourdomain" by your public domain name server (DNS) proxyServer.listen(80, "yourdomain");
With Secure Sockets Layer (SSL) encryption:
var https = require('https'), fs = require('fs'), httpProxy = require('http-proxy'); // This line refers to the node-http-proxy library. // Route secure websocket requests to the RemoteViz service // Replace "remoteviz_service_ip" by the RemoteViz service IP address var proxy = new httpProxy.createProxyServer({ target: { host: 'remoteviz_service_ip', port: 8080 ;} }); var options = { // Set the path to the private key file key: fs.readFileSync('ssl/ssl-private.key'), // Set the path to the public certificate file cert: fs.readFileSync('ssl/ssl-cert.crt'), // Set the path to the Intermediate Certificate ca: fs.readFileSync('ssl/CA_Bundle.pem') }; // Configure the HTTPS server to respond to all requests. var proxyServer = https.createServer(options, function (req, res) { /* HERE, write your HTTP server logic. The following example returns the index.html page to the client. if (req.url == '/index.html'){ var page = fs.readFileSync(__dirname + '/index.html'); res.writeHead(200, {'Content-Type': 'text/html'}); res.write(page); res.end(); } */ }); // Listen to the `upgrade` event and proxy the WebSocket requests. proxyServer.on('upgrade', function (req, socket, head) { proxy.ws(req, socket, head); }); // Web server IP address and port. Replace "yourdomain" by your public domain name server (DNS) proxyServer.listen(443, "yourdomain");
theRenderArea.connectTo("ws://127.0.0.1:8080/RenderAreaName");
by the line for using non-SSL:
theRenderArea.connectTo("ws://yourdomain/RemoteViz/RenderAreaName");
or by the line for using SSL:
theRenderArea.connectTo("wss://yourdomain/RemoteViz/RenderAreaName");