Skip to content

Commit

Permalink
fix: refine version in search page
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Oct 18, 2022
1 parent 5c934cd commit 6d091b7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions docusaurus-search-local/src/client/theme/SearchBar/fetchIndexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ export async function legacyFetchIndexes(
searchContext: string
): Promise<IndexesData> {
if (process.env.NODE_ENV === "production") {
const url = `${baseUrl}${searchIndexUrl.replace(
"{dir}",
searchContext ? `-${searchContext.replace(/\//g, "-")}` : ""
)}`;

// Catch potential attacks.
const fullUrl = new URL(url, location.origin);
if (fullUrl.origin !== location.origin) {
throw new Error("Unexpected version url");
}

const json = (await (
await fetch(
`${baseUrl}${searchIndexUrl.replace(
"{dir}",
searchContext ? `-${searchContext.replace(/\//g, "-")}` : ""
)}`
)
await fetch(url)
).json()) as SerializedIndex[];

const wrappedIndexes: WrappedIndex[] = json.map(
Expand Down

0 comments on commit 6d091b7

Please sign in to comment.