Skip to content

Commit

Permalink
Updated Documents page to not use a search key
Browse files Browse the repository at this point in the history
This change updates the page to rely on basic authentication rather
than a search key.

As part of that, we needed to create a proxy endpoint for search-ui
to post to, rather than going directly to the ent-search API.
  • Loading branch information
JasonStoltz committed Jun 23, 2021
1 parent fb5edb3 commit 8a1e666
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { i18n } from '@kbn/i18n';

import './search_experience.scss';

import { externalUrl } from '../../../../shared/enterprise_search_url';
import { HttpLogic } from '../../../../shared/http';
import { useLocalStorage } from '../../../../shared/use_local_storage';
import { EngineLogic } from '../../engine';

Expand Down Expand Up @@ -52,7 +52,8 @@ const DEFAULT_SORT_OPTIONS: SortOption[] = [

export const SearchExperience: React.FC = () => {
const { engine } = useValues(EngineLogic);
const endpointBase = externalUrl.enterpriseSearchUrl;
const { http } = useValues(HttpLogic);
const endpointBase = http.basePath.prepend('/api/app_search/search-ui');

const [showCustomizationModal, setShowCustomizationModal] = useState(false);
const openCustomizationModal = () => setShowCustomizationModal(true);
Expand All @@ -72,7 +73,9 @@ export const SearchExperience: React.FC = () => {
cacheResponses: false,
endpointBase,
engineName: engine.name,
searchKey: engine.apiKey,
additionalHeaders: {
'kbn-xsrf': true,
},
});

const searchProviderConfig = buildSearchUIConfig(connector, engine.schema || {}, fields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import { schema } from '@kbn/config-schema';

import { skipBodyValidation } from '../../lib/route_config_helpers';

import { RouteDependencies } from '../../plugin';

export function registerSearchRoutes({
Expand All @@ -36,4 +38,25 @@ export function registerSearchRoutes({
path: '/api/as/v1/engines/:engineName/search.json',
})
);

// For the Search UI routes below, Search UI always uses the full API path, like:
// "/api/as/v1/engines/{engineName}/search.json". We only have control over the base path
// in Search UI, so we created a common basepath of "/api/app_search/search-ui" here that
// Search UI can use.
//
// Search UI *also* uses the click tracking and query suggestion endpoints, however, since the
// App Search plugin doesn't use that portion of Search UI, we only set up a proxy for the search endpoint below.
router.post(
skipBodyValidation({
path: '/api/app_search/search-ui/api/as/v1/engines/{engineName}/search.json',
validate: {
params: schema.object({
engineName: schema.string(),
}),
},
}),
enterpriseSearchRequestHandler.createRequest({
path: '/api/as/v1/engines/:engineName/search.json',
})
);
}

0 comments on commit 8a1e666

Please sign in to comment.