Skip to content

Commit 7e88807

Browse files
authored
Merge pull request #53 from adobe-rnd/repoless-support
fix: repoless support
2 parents 11c2789 + 47ea1c0 commit 7e88807

File tree

7 files changed

+55
-14
lines changed

7 files changed

+55
-14
lines changed

src/steps/fetch-404.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import { setProduct404CacheHeaders } from './set-cache-headers.js';
2121
*/
2222
export default async function fetch404(state, req, res) {
2323
const {
24-
owner, repo, ref,
24+
owner, site, ref,
2525
} = state;
26-
const ret = await fetch(`https://${ref}--${repo}--${owner}.aem.live/404.html`);
26+
const ret = await fetch(`https://${ref}--${site}--${owner}.aem.live/404.html`);
2727
if (ret.status === 200) {
2828
// override last-modified if source-last-modified is set
2929
const lastModified = extractLastModified(ret.headers);

src/steps/fetch-edge-product.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import { extractLastModified, recordLastModified } from '../utils/last-modified.
2020
*/
2121
export default async function fetchEdgeContent(state, res) {
2222
const {
23-
info, owner, repo, ref, log,
23+
info, owner, site, ref, log,
2424
} = state;
2525
const { originalPath } = info;
2626

27-
const contentUrl = `https://${ref}--${repo}--${owner}.aem.live${originalPath}.plain.html`;
27+
const contentUrl = `https://${ref}--${site}--${owner}.aem.live${originalPath}.plain.html`;
2828
try {
2929
const contentRes = await fetch(contentUrl);
3030
if (contentRes.status === 200) {

src/steps/fetch-media.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import { extractLastModified, recordLastModified } from '../utils/last-modified.
1919
*/
2020
export default async function fetchMedia(state, res) {
2121
const {
22-
info, owner, repo,
22+
info, owner, site,
2323
} = state;
2424
const bucketId = 'adobe-commerce-catalog';
2525

26-
const key = `${owner}/${repo}/media/${info.originalFilename}`;
26+
const key = `${owner}/${site}/media/${info.originalFilename}`;
2727
const ret = await state.s3Loader.getObject(bucketId, key);
2828

2929
if (ret.status === 200) {

src/steps/fetch-productbus.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const INDEXER_URL_KEYS = ['index', 'merchant-center-feed', 'sitemap'];
2323
*/
2424
export default async function fetchContent(state, req, res) {
2525
const {
26-
info, owner, repo, config,
26+
info, owner, site, config,
2727
} = state;
2828
const bucketId = 'adobe-commerce-catalog';
2929
const { route } = config;
@@ -39,7 +39,7 @@ export default async function fetchContent(state, req, res) {
3939
urlKey = urlKey?.replace(/\.xml$/, '');
4040

4141
if (Object.keys(route.params).length === 1 && urlKey && !INDEXER_URL_KEYS.includes(urlKey)) {
42-
const headKey = `${owner}/${repo}/${storeCode}/${storeViewCode}/urlkeys/${urlKey}`;
42+
const headKey = `${owner}/${site}/${storeCode}/${storeViewCode}/urlkeys/${urlKey}`;
4343

4444
const headRes = await state.s3Loader.headObject(bucketId, headKey);
4545

@@ -58,12 +58,12 @@ export default async function fetchContent(state, req, res) {
5858
let key;
5959
if ((!sku && !INDEXER_URL_KEYS.includes(urlKey)) || (sku && !INDEXER_URL_KEYS.includes(sku))) {
6060
const slug = slugger(sku);
61-
key = `${owner}/${repo}/${storeCode}/${storeViewCode}/products/${slug}.json`;
61+
key = `${owner}/${site}/${storeCode}/${storeViewCode}/products/${slug}.json`;
6262
} else if (urlKey === 'index' || sku === 'index' || urlKey === 'sitemap' || sku === 'sitemap') {
6363
const id = req.params?.id ?? 'default';
64-
key = `${owner}/${repo}/${storeCode}/${storeViewCode}/index/${id}.json`;
64+
key = `${owner}/${site}/${storeCode}/${storeViewCode}/index/${id}.json`;
6565
} else if (urlKey === 'merchant-center-feed' || sku === 'merchant-center-feed') {
66-
key = `${owner}/${repo}/${storeCode}/${storeViewCode}/merchant-feed/default.json`;
66+
key = `${owner}/${site}/${storeCode}/${storeViewCode}/merchant-feed/default.json`;
6767
}
6868

6969
const ret = await state.s3Loader.getObject(bucketId, key);

test/product-html-pipe.test.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,46 @@ describe('Product HTML Pipe Test', () => {
9797
});
9898
});
9999

100+
it('renders a configurable product html from repoless site', async () => {
101+
const s3Loader = new FileS3Loader();
102+
const state = DEFAULT_STATE({
103+
...DEFAULT_CONFIG,
104+
site: 'repoless-site',
105+
}, {
106+
log: console,
107+
s3Loader,
108+
ref: 'main',
109+
path: '/products/product-configurable',
110+
partition: 'live',
111+
timer: {
112+
update: () => { },
113+
},
114+
});
115+
116+
state.site = 'repoless-site';
117+
state.info = getPathInfo('/products/product-configurable');
118+
const resp = await productHTMLPipe(
119+
state,
120+
new PipelineRequest(
121+
new URL('https://acme.com/products/product-configurable'),
122+
{
123+
headers: {
124+
'x-byo-cdn-type': 'fastly',
125+
},
126+
},
127+
),
128+
);
129+
assert.strictEqual(resp.status, 200);
130+
assert.ok(resp.body.includes('<h1 id="blitzmax-5000">BlitzMax 5000</h1>'));
131+
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
132+
'cache-control': 'max-age=7200, must-revalidate',
133+
'content-type': 'text/html; charset=utf-8',
134+
'last-modified': 'Fri, 30 Apr 2021 03:47:18 GMT',
135+
'surrogate-control': 'max-age=300, stale-while-revalidate=0',
136+
'surrogate-key': 'aVjSNe6DuUvP6Qt0 _H4KMAHPxerU_zHx E2NdXMQ8Jp-cg0zr mkywV26m8w1sg6tA main--repoless-site--org mRN24kMQcclw-dMQ',
137+
});
138+
});
139+
100140
it('renders a configurable product html with CDN cache control headers', async () => {
101141
const s3Loader = new FileS3Loader();
102142
const state = DEFAULT_STATE(DEFAULT_CONFIG, {
@@ -165,7 +205,7 @@ describe('Product HTML Pipe Test', () => {
165205
const dirname = path.dirname(fileURLToPath(import.meta.url));
166206
const fetchMockGlobal = fetchMock.mockGlobal();
167207
const html404 = await readFile(path.join(dirname, 'fixtures', 'product', '404.html'));
168-
fetchMockGlobal.get('https://main--helix-pages--adobe.aem.live/404.html', {
208+
fetchMockGlobal.get('https://main--site--adobe.aem.live/404.html', {
169209
body: html404,
170210
headers: {
171211
'cache-control': 'max-age=7200, must-revalidate',

test/product-index-pipe.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe('Product Index Pipe Test', () => {
151151

152152
const result = await productIndexPipe(state, new PipelineRequest(new URL('https://acme.com/products/index.json?id=404')));
153153
assert.strictEqual(result.status, 404);
154-
assert.strictEqual(result.headers.get('x-error'), 'failed to load adobe/helix-pages/main/default/index/404.json from product-bus: 404');
154+
assert.strictEqual(result.headers.get('x-error'), 'failed to load adobe/site/main/default/index/404.json from product-bus: 404');
155155
});
156156

157157
it('returns 404 for invalid path info', async () => {

test/rendering.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const DEFAULT_CONFIG = {
3232
contentBusId: 'foo-id',
3333
owner: 'blendify',
3434
repo: 'website',
35+
site: 'helix-pages',
3536
ref: 'main',
3637
cdn: {
3738
prod: {
@@ -110,7 +111,7 @@ describe('Rendering', () => {
110111
}
111112

112113
const fetchMockGlobal = fetchMock.mockGlobal();
113-
const productContentUrl = `https://${config.ref}--${config.repo}--${config.owner}.aem.live${url.pathname}.plain.html`;
114+
const productContentUrl = `https://${config.ref}--${config.site}--${config.owner}.aem.live${url.pathname}.plain.html`;
114115
if (productContent) {
115116
const edgeHtml = await readFile(path.resolve(__testdir, 'fixtures', 'product', 'product-content.html'), 'utf-8');
116117
fetchMockGlobal.get(productContentUrl, {

0 commit comments

Comments
 (0)