On Github dyercode / proxy-presentation
Error Server failed to start for port 8080: Address already in use
http://localhost:8080/
http://localhost:9090/rewards
HTTPS is tricky
Node.js does support https support and there are actually instructions for using it on the node-http-proxy github. The difficulty here is Grails use a Java keystore and the node implementation expects
Start of workaround
grails.tomcat.keystorePath = "/path/to/my/keystore" grails.tomcat.keystorePassword = "kspwd"
Commons-daemon is a pain
Binary installer found at nodejs.org
Install http-proxy plugin From the command line:
Create/navigate to directory you want to keep the proxy Install http-proxy via npmcd C:\devel\workspace\proxy npm install http-proxy(a package manager for node which supposedly doesn’t stand for anything)
proxy.js
var httpProxy = require('http-proxy'); var options = { router: { 'localhost/rewards': 'localhost:8081/rewards', 'localhost/thor': 'localhost:8082/thor', '': 'localhost:8080' } }; var proxyServer = httpProxy.createServer(options); proxyServer.listen(80);
The left (key) defines the paths (and domains) of requests to handle The right (value) is where to forward those requests to. They take regular expressions.
Basic http proxy. The options define the routes. There are a few options for syntax.
var httpProxy = require('http-proxy');Like a java import
var options = { router: { 'localhost/rewards': 'localhost:8081/rewards', 'localhost/thor': 'localhost:8082/thor', '': 'localhost:8080' } };
router object defines the routes to use.
There are other options such as for https or different types of routes, but we don't really need them
var proxyServer = httpProxy.createServer(options); proxyServer.listen(80);
creates an http proxy server with the options and save it into an object. Have it listen on port 80
cd C:\devel\workspace\proxy node proxy.js
BuildConfig.groovy
grails.server.port.http=8080If someone knows a clean way to have user specific grails configs please let me know.
npm install "Node Proxy"Application will be your path to the node executeable
C:\devel\software\node\bin\node.exeOptions will be the path to your node.js app.
C:\devel\workspace\proxy\proxy.js
I use cygwin so I just copied the executeable into the /usr/local/bin dir. A symlink or something would work too.
Optionally, you can provide the entire setup via the command line.
To Be Added