Skip to content

Commit

Permalink
fangli#39 Support elastic search on SSL. Currently, the config key es…
Browse files Browse the repository at this point in the history
…_using_ssl was unused.
  • Loading branch information
raghur committed Oct 7, 2014
1 parent 0c0173b commit be07644
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require('./lib/cas-auth.js').configureCas(express, app, config);

// Setup ES proxy
require('./lib/es-proxy').configureESProxy(app, config.es_host, config.es_port,
config.es_username, config.es_password);
config.es_username, config.es_password, config.es_using_ssl);

// Serve config.js for kibana3
// We should use special config.js for the frontend and point the ES to __es/
Expand Down
11 changes: 6 additions & 5 deletions lib/es-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* http://www.catonmat.net/http-proxy-in-nodejs/
*/
var http = require('http');
var https = require('https');

function proxyRequest(request, response, host, port, user, password, getProxiedRequestPath, isUI) {
function proxyRequest(request, response, host, port, user, password, useSSL, getProxiedRequestPath, isUI) {
var filteredHeaders = {};
Object.keys(request.headers).forEach(function(header) {
if (header === 'host') {
Expand Down Expand Up @@ -35,7 +36,7 @@ function proxyRequest(request, response, host, port, user, password, getProxiedR
options.auth = password ? user + ':' + password : user;
}

var proxyReq = http.request(options);
var proxyReq = useSSL ? https.request(options) : http.request(options);

proxyReq.addListener('error', function(err){
response.status(500).send('Unable to process your request, ' + err.code);
Expand Down Expand Up @@ -83,15 +84,15 @@ function proxyRequest(request, response, host, port, user, password, getProxiedR
});
}

exports.configureESProxy = function(app, esHost, esPort, esUser, esPassword) {
exports.configureESProxy = function(app, esHost, esPort, esUser, esPassword, useSSL) {
app.use("/__es", function(request, response, next) {
proxyRequest(request, response, esHost, esPort, esUser, esPassword,
proxyRequest(request, response, esHost, esPort, esUser, esPassword, useSSL,
function getProxiedRequestPath(request) {
return request.url;
});
});
app.use("/_plugin", function(request, response, next) {
proxyRequest(request, response, esHost, esPort, esUser, esPassword,
proxyRequest(request, response, esHost, esPort, esUser, esPassword, useSSL,
function getProxiedRequestPath(request) {
return request.originalUrl;
}, true);
Expand Down

0 comments on commit be07644

Please sign in to comment.