Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

solr-proxy

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

solr-proxy - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

8

bin/solr-proxy.js
#!/usr/bin/env node
var cli = require('../lib/cli');
var argv = require('minimist')(process.argv.slice(2));
var SolrProxy = require('../');
var cli = require('../lib/cli')
var argv = require('minimist')(process.argv.slice(2))
var SolrProxy = require('../')
cli.argv(argv, console.log, SolrProxy);
cli.argv(argv, console.log, SolrProxy)

@@ -1,6 +0,6 @@

var httpProxy = require('http-proxy'),
url = require('url'),
extend = require('xtend'),
debug = require('debug')('solr-proxy'),
SolrProxy = {};
var httpProxy = require('http-proxy')
var url = require('url')
var extend = require('xtend')
var debug = require('debug')('solr-proxy')
var SolrProxy = {}

@@ -13,14 +13,14 @@ /*

*/
var validateRequest = function(request, options) {
var parsedUrl = url.parse(request.url, true),
path = parsedUrl.pathname,
queryParams = Object.keys(parsedUrl.query);
var validateRequest = function (request, options) {
var parsedUrl = url.parse(request.url, true)
var path = parsedUrl.pathname
var queryParams = Object.keys(parsedUrl.query)
return options.validHttpMethods.indexOf(request.method) !== -1 &&
options.validPaths.indexOf(path) !== -1 &&
queryParams.every(function(p) {
var paramPrefix = p.split('.')[0]; // invalidate not just "stream", but "stream.*"
return options.invalidParams.indexOf(paramPrefix) === -1;
});
};
queryParams.every(function (p) {
var paramPrefix = p.split('.')[0] // invalidate not just "stream", but "stream.*"
return options.invalidParams.indexOf(paramPrefix) === -1
})
}

@@ -36,48 +36,48 @@ var defaultOptions = {

}
};
}
var createServer = function(options) {
var proxy = httpProxy.createProxyServer({target: options.backend});
var createServer = function (options) {
var proxy = httpProxy.createProxyServer({target: options.backend})
proxy.on('error', function(err, req, res) {
res.writeHead(502, { 'Content-Type': 'text/plain' });
res.end('Proxy error: ' + err);
});
proxy.on('error', function (err, req, res) {
res.writeHead(502, { 'Content-Type': 'text/plain' })
res.end('Proxy error: ' + err)
})
var createServer;
var createServer
if (options.ssl) {
const https = require('https');
createServer = (callback) => https.createServer(options.ssl, callback);
const https = require('https')
createServer = (callback) => https.createServer(options.ssl, callback)
} else {
const http = require('http');
createServer = http.createServer;
const http = require('http')
createServer = http.createServer
}
// adapted from https://git.io/k5dCxQ
var server = createServer(function(request, response) {
var server = createServer(function (request, response) {
if (validateRequest(request, options)) {
debug('ALLOWED: ' + request.method + ' ' + request.url);
proxy.web(request, response);
debug('ALLOWED: ' + request.method + ' ' + request.url)
proxy.web(request, response)
} else {
debug('DENIED: ' + request.method + ' ' + request.url);
response.writeHead(403, 'Illegal request');
response.write('solrProxy: access denied\n');
response.end();
debug('DENIED: ' + request.method + ' ' + request.url)
response.writeHead(403, 'Illegal request')
response.write('solrProxy: access denied\n')
response.end()
}
});
return server;
};
})
return server
}
SolrProxy.start = function(port, options) {
options = options || {};
options.backend = extend(defaultOptions.backend, options.backend);
options = extend(defaultOptions, options);
SolrProxy.start = function (port, options) {
options = options || {}
options.backend = extend(defaultOptions.backend, options.backend)
options = extend(defaultOptions, options)
port = port || options.listenPort;
port = port || options.listenPort
var server = createServer(options);
server.listen(port);
return server;
};
var server = createServer(options)
server.listen(port)
return server
}
module.exports = SolrProxy;
module.exports = SolrProxy
var createProxyOptions = function (argv) {
var proxyOptions = {
backend: {}
};
}
if (argv.backendPort) {
proxyOptions.backend.port = argv.backendPort;
proxyOptions.backend.port = argv.backendPort
}
if (argv.backendHost) {
proxyOptions.backend.host = argv.backendHost;
proxyOptions.backend.host = argv.backendHost
}
if (argv.validMethods) {
proxyOptions.validHttpMethods = argv.validMethods.split(',');
proxyOptions.validHttpMethods = argv.validMethods.split(',')
}
if (argv.invalidParams) {
proxyOptions.invalidParams = argv.invalidParams.split(',');
proxyOptions.invalidParams = argv.invalidParams.split(',')
}
if (argv.validPaths) {
proxyOptions.validPaths = argv.validPaths.split(',');
proxyOptions.validPaths = argv.validPaths.split(',')
}
return proxyOptions;
};
return proxyOptions
}
module.exports = function(argv, stdout, SolrProxy) {
module.exports = function (argv, stdout, SolrProxy) {
var usageMessage = 'Usage: solr-proxy [options]\n' +

@@ -44,13 +43,13 @@ '\n' +

' --version, -v Show version\n' +
' --help, -h Show this message';
' --help, -h Show this message'
if (argv.help || argv.h) {
stdout(usageMessage);
return;
stdout(usageMessage)
return
}
if (argv.version || argv.v) {
var version = require('../../package.json').version;
stdout(version);
return;
var version = require('../../package.json').version
stdout(version)
return
}

@@ -60,9 +59,9 @@

// quiet mode, change stdout to a no-op
stdout = function () {};
stdout = function () {}
}
var proxyOptions = createProxyOptions(argv);
var proxyOptions = createProxyOptions(argv)
SolrProxy.start(argv.port, proxyOptions);
stdout('solr-proxy is running...');
};
SolrProxy.start(argv.port, proxyOptions)
stdout('solr-proxy is running...')
}
module.exports = {
argv: require('./argv')
};
}

@@ -10,3 +10,3 @@ {

],
"version": "2.1.0",
"version": "2.1.1",
"author": "Rich Trott <rtrott@gmail.com>",

@@ -18,3 +18,3 @@ "bugs": {

"scripts": {
"test": "lab -t 100 test"
"test": "standard && lab -t 100 test"
},

@@ -37,8 +37,10 @@ "bin": {

"http-proxy": "^1.10.1",
"minimist": "^1.2.0",
"xtend": "^4.0.0"
},
"devDependencies": {
"code": "^3.0.2",
"lab": "^15.4.5",
"request": "^2.86.0"
"code": "^5.2.0",
"lab": "^15.5.0",
"request": "^2.86.0",
"standard": "^11.0.1"
},

@@ -45,0 +47,0 @@ "engines": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc