kibana-123
Version:
Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic
47 lines (40 loc) • 1.54 kB
JavaScript
import { defaults, omit, trimLeft, trimRight } from 'lodash';
import { parse as parseUrl, format as formatUrl, resolve } from 'url';
import filterHeaders from './filter_headers';
import setHeaders from './set_headers';
export default function mapUri(cluster, proxyPrefix) {
function joinPaths(pathA, pathB) {
return trimRight(pathA, '/') + '/' + trimLeft(pathB, '/');
}
return function (request, done) {
const {
protocol: esUrlProtocol,
slashes: esUrlHasSlashes,
auth: esUrlAuth,
hostname: esUrlHostname,
port: esUrlPort,
pathname: esUrlBasePath,
query: esUrlQuery
} = parseUrl(cluster.getUrl(), true);
// copy most url components directly from the elasticsearch.url
const mappedUrlComponents = {
protocol: esUrlProtocol,
slashes: esUrlHasSlashes,
auth: esUrlAuth,
hostname: esUrlHostname,
port: esUrlPort
};
// pathname
const reqSubPath = request.path.replace(proxyPrefix, '');
mappedUrlComponents.pathname = joinPaths(esUrlBasePath, reqSubPath);
// querystring
const mappedQuery = defaults(omit(request.query, '_'), esUrlQuery);
if (Object.keys(mappedQuery).length) {
mappedUrlComponents.query = mappedQuery;
}
const filteredHeaders = filterHeaders(request.headers, cluster.getRequestHeadersWhitelist());
const mappedHeaders = setHeaders(filteredHeaders, cluster.getCustomHeaders());
const mappedUrl = formatUrl(mappedUrlComponents);
done(null, mappedUrl, mappedHeaders);
};
};