diff --git a/plugins/search-backend/src/index.ts b/plugins/search-backend/src/index.ts index 7612c392a2..90a67d7605 100644 --- a/plugins/search-backend/src/index.ts +++ b/plugins/search-backend/src/index.ts @@ -15,3 +15,4 @@ */ export * from './service/router'; +export * from './types'; diff --git a/plugins/search-backend/src/service/standaloneServer.ts b/plugins/search-backend/src/service/standaloneServer.ts index e1212ee5a7..4efc02de6f 100644 --- a/plugins/search-backend/src/service/standaloneServer.ts +++ b/plugins/search-backend/src/service/standaloneServer.ts @@ -13,21 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ import { createServiceBuilder } from '@backstage/backend-common'; import { Server } from 'http'; @@ -51,7 +36,7 @@ export async function startStandaloneServer( const service = createServiceBuilder(module) .enableCors({ origin: 'http://localhost:3000' }) - .addRouter('/search', router); + .addRouter('/api/search', router); return await service.start().catch(err => { logger.error(err); diff --git a/plugins/search/package.json b/plugins/search/package.json index 8003843d8d..6fa80cda54 100644 --- a/plugins/search/package.json +++ b/plugins/search/package.json @@ -32,6 +32,7 @@ "@backstage/core": "^0.7.2", "@backstage/catalog-model": "^0.7.3", "@backstage/plugin-catalog-react": "^0.1.2", + "@backstage/plugin-search-backend": "^0.1.1", "@backstage/theme": "^0.2.4", "@material-ui/core": "^4.11.0", "@material-ui/icons": "^4.9.1", diff --git a/plugins/search/src/apis.ts b/plugins/search/src/apis.ts index 9d88227a44..65490c3c37 100644 --- a/plugins/search/src/apis.ts +++ b/plugins/search/src/apis.ts @@ -15,7 +15,10 @@ */ import { Entity, ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model'; +import { DiscoveryApi } from '@backstage/core'; import { CatalogApi } from '@backstage/plugin-catalog-react'; +import { SearchQuery, SearchResultSet } from '@backstage/plugin-search-backend'; +import qs from 'qs'; export type Result = { name: string; @@ -30,9 +33,11 @@ export type SearchResults = Array; class SearchApi { private catalogApi: CatalogApi; + private discoveryApi: DiscoveryApi; - constructor(catalogApi: CatalogApi) { + constructor(catalogApi: CatalogApi, discoveryApi: DiscoveryApi) { this.catalogApi = catalogApi; + this.discoveryApi = discoveryApi; } private async entities() { @@ -56,6 +61,18 @@ class SearchApi { public getSearchResult(): Promise { return this.entities(); } + + // @todo Productionalize as we implement search milestones. + public async _alphaPerformSearch( + query: SearchQuery, + ): Promise { + const queryString = qs.stringify(query); + const url = `${await this.discoveryApi.getBaseUrl( + 'search/query', + )}?${queryString}`; + const response = await fetch(url); + return response.json(); + } } export default SearchApi; diff --git a/plugins/search/src/components/SearchResult/SearchResult.tsx b/plugins/search/src/components/SearchResult/SearchResult.tsx index 7f4d31a6df..141b7684cd 100644 --- a/plugins/search/src/components/SearchResult/SearchResult.tsx +++ b/plugins/search/src/components/SearchResult/SearchResult.tsx @@ -14,6 +14,7 @@ * limitations under the License. */ import { + discoveryApiRef, EmptyState, Link, Progress, @@ -117,6 +118,7 @@ const TableHeader = ({ export const SearchResult = ({ searchQuery }: SearchResultProps) => { const catalogApi = useApi(catalogApiRef); + const discoveryApi = useApi(discoveryApiRef); const [showFilters, toggleFilters] = useState(false); const [selectedFilters, setSelectedFilters] = useState({ @@ -126,7 +128,7 @@ export const SearchResult = ({ searchQuery }: SearchResultProps) => { const [filteredResults, setFilteredResults] = useState([]); - const searchApi = new SearchApi(catalogApi); + const searchApi = new SearchApi(catalogApi, discoveryApi); const { loading, error, value: results } = useAsync(() => { return searchApi.getSearchResult();