Skip to content

Commit

Permalink
Use generated fed-modules.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperkid123 committed Nov 20, 2024
1 parent cbea8ff commit d99cd66
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/state/atoms/localSearchAtom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { atom } from 'jotai';
import { Orama, create, insert } from '@orama/orama';

import { getChromeStaticPathname } from '../../utils/common';
import { GENERATED_SEARCH_FLAG, getChromeStaticPathname } from '../../utils/common';
import axios from 'axios';
import { NavItemPermission } from '../../@types/types';

Expand Down Expand Up @@ -29,7 +29,6 @@ type SearchEntry = {
altTitle?: string[];
};

const GENERATED_SEARCH_FLAG = '@chrome:generated-search-index';
type GeneratedSearchIndexResponse = {
alt_title?: string[];
id: string;
Expand Down
13 changes: 10 additions & 3 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ const fedModulesheaders = {
Expires: '0',
};

export const GENERATED_SEARCH_FLAG = '@chrome:generated-search-index';

// FIXME: Remove once qaprodauth is dealt with
// can't use /beta because it will ge redirected by Akamai to /preview and we don't have any assets there\\
// Always use stable
Expand All @@ -356,10 +358,14 @@ const loadCSCFedModules = () =>
headers: fedModulesheaders,
});

export const loadFedModules = async () =>
Promise.all([
export const loadFedModules = async () => {
const fedModulesPath =
localStorage.getItem(GENERATED_SEARCH_FLAG) === 'true'
? '/api/chrome-service/v1/static/fed-modules-generated.json'
: `${getChromeStaticPathname('modules')}/fed-modules.json`;
return Promise.all([
axios
.get(`${getChromeStaticPathname('modules')}/fed-modules.json`, {
.get(fedModulesPath, {
headers: fedModulesheaders,
})
.catch(loadCSCFedModules),
Expand All @@ -370,6 +376,7 @@ export const loadFedModules = async () =>
}
return staticConfig;
});
};

export const generateRoutesList = (modules: { [key: string]: ChromeModule }) =>
Object.entries(modules)
Expand Down

0 comments on commit d99cd66

Please sign in to comment.