Skip to content

Commit

Permalink
Expose generated search index.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperkid123 committed Nov 14, 2024
1 parent 8c70b73 commit 2ebc23a
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion rest/util/createChromeConfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
const (
fedModulesPath = "static/fed-modules-generated.json"
staticFedModulesPath = "static/stable/%s/modules/fed-modules.json"
searchIndexPath = "static/search-index-generated.json"
)

func getLegacyConfigFile(path string, env string) ([]byte, error) {
Expand Down Expand Up @@ -60,6 +61,22 @@ func parseFedModules(fedModulesConfig string, env string) ([]byte, error) {
return res, err
}

func parseSearchIndex(searchIndexConfig string, env string) ([]byte, error) {
si := []interface{}{}

if searchIndexConfig == "" {
logrus.Warn("FEO_SEARCH_INDEX is not set, using empty configuration")
} else {
err := json.Unmarshal([]byte(searchIndexConfig), &si)
if err != nil {
return nil, err
}
}

res, err := json.MarshalIndent(si, "", " ")
return res, err
}

func writeConfigFile(config []byte, path string) error {
cwd, err := filepath.Abs(".")
if err != nil {
Expand Down Expand Up @@ -88,7 +105,7 @@ func CreateChromeConfiguration() {
}

fedModulesVar := os.Getenv("FEO_FED_MODULES")
// searchVar := os.Getenv("FEO_SEARCH_INDEX")
searchVar := os.Getenv("FEO_SEARCH_INDEX")
// serviceTilesVar := os.Getenv("FEO_SERVICE_TILES")
// widgetRegistryVar := os.Getenv("FEO_WIDGET_REGISTRY")

Expand All @@ -102,4 +119,14 @@ func CreateChromeConfiguration() {
if err != nil {
panic(err)
}

searchIndex, err := parseSearchIndex(searchVar, env)
if err != nil {
panic(fmt.Sprintf("Error parsing FEO_SEARCH_INDEX: %v", err))
}

err = writeConfigFile(searchIndex, searchIndexPath)
if err != nil {
panic(err)
}
}

0 comments on commit 2ebc23a

Please sign in to comment.