fix: changing facets reverted to combined search
3 files changed, 16 insertions(+), 7 deletions(-)
M internal/config/structs.go → internal/config/structs.go
@@ -5,6 +5,7 @@ // keep config structs here so that lll ignores the long lines (go doesn't support multi-line struct tags) import ( "fmt" + "net/url" "path/filepath" "strings"@@ -90,3 +91,14 @@ func (source *Source) JoinFilePath(name string) string { //nolint:forbidigo // is not absolute return filepath.Join("sources", source.Key, name) } + +func (source *Source) LocalURL() *url.URL { + p, err := url.JoinPath("/", source.Importer.String(), source.Key, "/") + if err != nil { + panic(err.Error()) + } + + return &url.URL{ + Path: p, + } +}
M internal/server/global.go → internal/server/global.go
@@ -37,9 +37,9 @@ source: source, mux: http.NewServeMux(), } - h.mux.HandleFunc("/search", h.Search) - h.mux.HandleFunc("/{id}", h.Detail) - h.mux.HandleFunc("/opensearch.xml", h.OpenSearchXML) + h.mux.HandleFunc(source.LocalURL().JoinPath("/search").String(), h.Search) + h.mux.HandleFunc(source.LocalURL().JoinPath("/{id}").String(), h.Detail) + h.mux.HandleFunc(source.LocalURL().JoinPath("/opensearch.xml").String(), h.OpenSearchXML) return h }
M internal/server/mux.go → internal/server/mux.go
@@ -95,10 +95,7 @@ }) } for _, source := range cfg.Importer.Sources { - sh := handler.NewSourceHandler(source) - importerPath := path.Join("/", source.Importer.String(), source.Key) - - mux.Handle(importerPath+"/", http.StripPrefix(importerPath, sh)) + mux.Handle(source.LocalURL().String(), handler.NewSourceHandler(source)) } top := http.NewServeMux()