Allow elasticsearch URL be relative

Like https://myweblog/elasticsearch

url.resolve will strip a path component and assume elasticsearch sits at
the root URL.
This commit is contained in:
Markus Frosch 2015-09-09 14:28:54 +02:00
parent cfd7aea64c
commit 864b491b51

View file

@ -5,8 +5,10 @@ module.exports = function mapUri(server, prefix) {
return function (request, done) {
var path = request.path.replace('/elasticsearch', '');
var url = config.get('elasticsearch.url');
if (!/\/$/.test(url)) url += '/';
if (path) url = resolve(url, path);
if (path) {
if (/\/$/.test(url)) url = url.substring(0, url.length - 1);
url += path;
}
var query = querystring.stringify(request.query);
if (query) url += '?' + query;
done(null, url);