Strip the trailing slash from the direct search API URL (#4861)

This commit is contained in:
Peter White
2026-11-27 19:47:14 +01:00
committed by GitHub
parent c2daee4a8a
commit 1c8da29d46
3 changed files with 9 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"gitbook": patch
---
Strip the trailing slash from the API URL used by browser site search.
@@ -3,10 +3,10 @@ import { afterEach, describe, expect, it, spyOn } from 'bun:test';
import { SEARCH_FALLBACK_HEADER, createSearchPassStore } from './search-pass-store';
import type { DirectSearchProps } from '@/lib/search-results';
const endpoint = 'https://api.gitbook.com/v1/orgs/org_1/sites/site_1/search';
const endpoint = 'https://api.gitbook.com/cache/v1/orgs/org_1/sites/site_1/search';
const proxyURL = '/~gitbook/search-direct/orgs/org_1/sites/site_1';
const directSearch: DirectSearchProps = {
apiURL: 'https://api.gitbook.com',
apiURL: 'https://api.gitbook.com/cache/',
organizationId: 'org_1',
siteId: 'site_1',
proxyURL,
@@ -5,6 +5,7 @@ import type { SearchRecordResult, SearchSpaceResult } from '@gitbook/api';
import type { OrderedComputedResult, SearchSiteContentScope } from './search-types';
import { getEmbeddableLinker } from '@/lib/embeddable-linker';
import { createSiteLinker } from '@/lib/links';
import { removeTrailingSlash } from '@/lib/paths';
import {
type DirectSearchProps,
computePublishedSearchResults,
@@ -157,7 +158,7 @@ export function createSearchPassStore(directSearch: DirectSearchProps | undefine
let pass = state;
const { apiURL, organizationId, siteId, proxyURL } = directSearch;
const usingProxy = useProxy;
let url = `${apiURL}/v1/orgs/${organizationId}/sites/${siteId}/search`;
let url = `${removeTrailingSlash(apiURL)}/v1/orgs/${organizationId}/sites/${siteId}/search`;
if (usingProxy) {
url = proxyURL;
}