From 0e3d8d6931874d5b11bfcd85144d1b1198898b6d Mon Sep 17 00:00:00 2001 From: Andre Wanlin <67169551+awanlin@users.noreply.github.com> Date: Thu, 27 Apr 2023 12:08:34 -0500 Subject: [PATCH] Fixed search 404 casued by URL encoding change Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com> --- .changeset/calm-wolves-taste.md | 5 +++++ plugins/search/src/apis.test.ts | 8 ++++---- plugins/search/src/apis.ts | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .changeset/calm-wolves-taste.md diff --git a/.changeset/calm-wolves-taste.md b/.changeset/calm-wolves-taste.md new file mode 100644 index 0000000000..ec0a7fb4f0 --- /dev/null +++ b/.changeset/calm-wolves-taste.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-search': patch +--- + +Fixed 404 Error when fetching search results due to URL encoding changes diff --git a/plugins/search/src/apis.test.ts b/plugins/search/src/apis.test.ts index 1c8f60d8e7..7996ad3fa3 100644 --- a/plugins/search/src/apis.test.ts +++ b/plugins/search/src/apis.test.ts @@ -51,8 +51,8 @@ describe('apis', () => { it('Fetch is called with expected URL (including stringified Q params)', async () => { await client.query(query); - expect(getBaseUrl).toHaveBeenLastCalledWith('search/query'); - expect(fetch).toHaveBeenLastCalledWith(`${baseUrl}?term=`, { + expect(getBaseUrl).toHaveBeenLastCalledWith('search'); + expect(fetch).toHaveBeenLastCalledWith(`${baseUrl}/query?term=`, { headers: {}, }); }); @@ -63,8 +63,8 @@ describe('apis', () => { identityApi: createIdentityApiMock(withToken), }); await authedClient.query(query); - expect(getBaseUrl).toHaveBeenLastCalledWith('search/query'); - expect(fetch).toHaveBeenLastCalledWith(`${baseUrl}?term=`, { + expect(getBaseUrl).toHaveBeenLastCalledWith('search'); + expect(fetch).toHaveBeenLastCalledWith(`${baseUrl}/query?term=`, { headers: { Authorization: `Bearer ${token}` }, }); }); diff --git a/plugins/search/src/apis.ts b/plugins/search/src/apis.ts index 208ad98b0a..eb5f47a65c 100644 --- a/plugins/search/src/apis.ts +++ b/plugins/search/src/apis.ts @@ -37,8 +37,8 @@ export class SearchClient implements SearchApi { const { token } = await this.identityApi.getCredentials(); const queryString = qs.stringify(query); const url = `${await this.discoveryApi.getBaseUrl( - 'search/query', - )}?${queryString}`; + 'search', + )}/query?${queryString}`; const response = await fetch(url, { headers: token ? { Authorization: `Bearer ${token}` } : {}, });