generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 174
/
aem.js
25 lines (25 loc) · 973 Bytes
/
aem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
export async function withAem(originalFetch) {
return async ({ pathname, searchParams }) => {
if (/cf\/fragments\/search/.test(pathname)) {
// TODO add conditional use case.
return originalFetch(
'/test/mocks/sites/cf/fragments/search/default.json',
);
} else if (/cf\/fragments/.test(pathname) && searchParams.has('path')) {
const path = searchParams.get('path');
const item = await originalFetch(
'/test/mocks/sites/cf/fragments/search/default.json',
)
.then((res) => res.json())
.then(({ items }) => items.find((item) => item.path === path));
if (item) {
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve({ items: [item] }),
});
}
}
return false;
};
}