Skip to content

Commit

Permalink
fix: urljoin on basepath (#1207)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Jul 26, 2024
1 parent 013b849 commit 003c538
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/ui/app/src/api-playground/PlaygroundContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const fetcher = async (url: string) => {

export const PlaygroundContextProvider: FC = () => {
const basePath = useBasePath();
const key = urljoin(basePath ?? "", "/api/fern-docs/resolve-api");
// note: if the first argument of urjoin is "", it will strip the leading slash. `|| "/"` ensures "" -> "/"
const key = urljoin(basePath || "/", "/api/fern-docs/resolve-api");

const { data } = useSWR<Record<string, ResolvedRootPackage> | null>(key, fetcher, {
revalidateOnFocus: false,
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/app/src/services/useApiKeyInjectionConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const DEFAULT = { enabled: false as const };

export function useApiKeyInjectionConfig(): APIKeyInjectionConfig {
const basePath = useBasePath();
const key = urljoin(basePath ?? "", API_KEY_INJECTION_ROUTE);
// note: if the first argument of urjoin is "", it will strip the leading slash. `|| "/"` ensures "" -> "/"
const key = urljoin(basePath || "/", API_KEY_INJECTION_ROUTE);

const { data } = useSWR<APIKeyInjectionConfig>(
key,
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/app/src/services/useSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export function useSearchConfig(): [SearchConfig, refresh: () => void] {
return [{ isAvailable: false }, noop];
}

const key = urljoin(basePath ?? "", "/api/fern-docs/search");
// note: if the first argument of urjoin is "", it will strip the leading slash. `|| "/"` ensures "" -> "/"
const key = urljoin(basePath || "/", "/api/fern-docs/search");

const { data } = useSWR<SearchConfig>(key, (url: string) => fetch(url).then((res) => res.json()), {
refreshInterval: 1000 * 60 * 60 * 2, // 2 hours
Expand Down
6 changes: 4 additions & 2 deletions packages/ui/docs-bundle/src/utils/getDocsPageProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ async function convertDocsToDocsPageProps({
theme: docs.baseUrl.domain.includes("cohere") ? "cohere" : "default",
};

props.fallback[urljoin(docs.baseUrl.basePath ?? "", "/api/fern-docs/search")] = await getSearchConfig(
// note: if the first argument of urjoin is "", it will strip the leading slash. `|| "/"` ensures "" -> "/"
props.fallback[urljoin(docs.baseUrl.basePath || "/", "/api/fern-docs/search")] = await getSearchConfig(
xFernHost,
docs.definition.search,
);
Expand All @@ -392,7 +393,8 @@ async function convertDocsToDocsPageProps({
}

const apiKeyInjectionConfig = await getAPIKeyInjectionConfigNode(xFernHost, cookies);
props.fallback[urljoin(docs.baseUrl.basePath ?? "", "/api/fern-docs/auth/api-key-injection")] =
// note: if the first argument of urjoin is "", it will strip the leading slash. `|| "/"` ensures "" -> "/"
props.fallback[urljoin(docs.baseUrl.basePath || "/", "/api/fern-docs/auth/api-key-injection")] =
apiKeyInjectionConfig;

return {
Expand Down

0 comments on commit 003c538

Please sign in to comment.