Skip to content

Commit bcafd96

Browse files
committed
fix(og): map 'foreign beer' category to international-beer API endpoint
The OG preview handler derives the API endpoint name directly from the URL's category param. For foreign beer drinks the category field value is 'foreign beer' (with a space) but the API endpoint is 'international-beer', so the handler fetched a non-existent URL and silently fell back to the plain SPA — no OG metadata was injected. Add a CATEGORY_TO_ENDPOINT lookup in fetchDrinkData so 'foreign beer' resolves to 'international-beer.json', matching what the Flutter app uses when loading these drinks.
1 parent ec87295 commit bcafd96

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

functions/_lib/drink-preview.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ const CRAWLER_UA_PATTERNS = [
1212
const DATA_BASE_URL = 'https://data.cambeerfestival.app';
1313
const OG_IMAGE_URL = 'https://cambeerfestival.app/icons/Icon-512.png';
1414

15+
// Product category field values don't always match their API endpoint names.
16+
const CATEGORY_TO_ENDPOINT = {
17+
'foreign beer': 'international-beer',
18+
};
19+
1520
export function isCrawler(userAgent) {
1621
if (!userAgent) return false;
1722
const ua = userAgent.toLowerCase();
@@ -59,7 +64,8 @@ export function buildOgTags(product, producer, canonicalUrl) {
5964
}
6065

6166
export async function fetchDrinkData(festivalId, category) {
62-
const url = `${DATA_BASE_URL}/${encodeURIComponent(festivalId)}/${encodeURIComponent(category)}.json`;
67+
const endpoint = CATEGORY_TO_ENDPOINT[category] ?? category;
68+
const url = `${DATA_BASE_URL}/${encodeURIComponent(festivalId)}/${encodeURIComponent(endpoint)}.json`;
6369
const response = await fetch(url);
6470
if (!response.ok) return null;
6571
const data = await response.json();

functions/test/drink-preview.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,17 @@ describe('fetchDrinkData', () => {
263263
'https://data.cambeerfestival.app/cbf2025/beer.json',
264264
);
265265
});
266+
267+
it('maps "foreign beer" category to "international-beer" endpoint', async () => {
268+
const mockFetch = vi.fn().mockResolvedValue({
269+
ok: true,
270+
json: () => Promise.resolve({ producers: [] }),
271+
});
272+
vi.stubGlobal('fetch', mockFetch);
273+
await fetchDrinkData('cbf2026', 'foreign beer');
274+
expect(mockFetch).toHaveBeenCalledWith(
275+
'https://data.cambeerfestival.app/cbf2026/international-beer.json',
276+
);
277+
});
266278
});
267279

0 commit comments

Comments
 (0)