From c98e2d39c7543e098ad474cc9906b4ab9c895a52 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Sat, 29 Feb 2020 11:11:43 +0100 Subject: [PATCH] Fixed search on 404 pages --- .../javascripts/workers/search/_/index.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/assets/javascripts/workers/search/_/index.ts b/src/assets/javascripts/workers/search/_/index.ts index 9717f9d16..683846a00 100644 --- a/src/assets/javascripts/workers/search/_/index.ts +++ b/src/assets/javascripts/workers/search/_/index.ts @@ -26,6 +26,7 @@ import { map, pluck, shareReplay, + switchMap, take, withLatestFrom } from "rxjs/operators" @@ -117,13 +118,16 @@ export function setupSearchWorker( /* Fetch index if it wasn't passed explicitly */ const index$ = typeof index !== "undefined" ? from(index) - : ajax({ - url: `${base}/search/search_index.json`, - responseType: "json", - withCredentials: true - }) - .pipe( - pluck("response") + : origin$ + .pipe( + switchMap(origin => ajax({ + url: `${origin}/search/search_index.json`, + responseType: "json", + withCredentials: true + }) + .pipe( + pluck("response") + )) ) /* Send index to worker */