Fixed #1877: 404 on search index when search is disabled

This commit is contained in:
squidfunk
2020-08-22 17:36:27 +02:00
parent f46334a955
commit 989b8597c5
6 changed files with 32 additions and 29 deletions

View File

@@ -237,32 +237,35 @@ export function initialize(config: unknown) {
/* ----------------------------------------------------------------------- */
/* Search worker */
const worker$ = defer(() => {
const index = config.search && config.search.index
? config.search.index
: undefined
/* Search worker - only if search is present */
const worker$ = useComponent("search")
.pipe(
switchMap(() => defer(() => {
const index = config.search && config.search.index
? config.search.index
: undefined
/* Fetch index if it wasn't passed explicitly */
const index$ = typeof index !== "undefined"
? from(index)
: base$
.pipe(
switchMap(base => ajax({
url: `${base}/search/search_index.json`,
responseType: "json",
withCredentials: true
})
.pipe<SearchIndex>(
pluck("response")
/* Fetch index if it wasn't passed explicitly */
const index$ = typeof index !== "undefined"
? from(index)
: base$
.pipe(
switchMap(base => ajax({
url: `${base}/search/search_index.json`,
responseType: "json",
withCredentials: true
})
.pipe<SearchIndex>(
pluck("response")
)
)
)
)
)
return of(setupSearchWorker(config.search.worker, {
base$, index$
}))
})
return of(setupSearchWorker(config.search.worker, {
base$, index$
}))
}))
)
/* ----------------------------------------------------------------------- */