Skip to content

Commit 7c0f95a

Browse files
committed
fix: support public confifg
1 parent 2459048 commit 7c0f95a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/config.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import { errorWithResponse } from './util.js';
13+
import { errorWithResponse, ffetch } from './util.js';
14+
15+
/** @type {'CONFIG_SERVICE' | 'STORAGE'} */
16+
const SOURCE = 'CONFIG_SERVICE';
1417

1518
/**
1619
* @param {string[]} patterns - An array of pattern strings to match against.
@@ -47,7 +50,18 @@ export async function resolveConfig(ctx, overrides = {}) {
4750
/**
4851
* @type {ConfigMap}
4952
*/
50-
const confMap = await ctx.env.CONFIGS.get(siteKey, 'json');
53+
let confMap;
54+
if (SOURCE === 'STORAGE') {
55+
confMap = await ctx.storage.get(siteKey, 'json');
56+
} else {
57+
const res = await ffetch(`https://main--${site}--${org}.aem.page/config.json`);
58+
if (res.status === 404) {
59+
throw errorWithResponse(404, 'config not found');
60+
}
61+
const json = await res.json();
62+
confMap = json.public?.mixerConfig;
63+
}
64+
5165
if (!confMap) {
5266
return null;
5367
}

src/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* @param {string} url - The URL to fetch.
15-
* @param {import("@cloudflare/workers-types").RequestInit } init - The request init.
15+
* @param {import("@cloudflare/workers-types").RequestInit} [init] - The request init.
1616
* @returns {Promise<Response>} - A promise that resolves to the response.
1717
*/
1818
export async function ffetch(url, init) {

0 commit comments

Comments
 (0)