mirror of
https://github.com/vercel/commerce.git
synced 2025-05-20 08:26:59 +00:00
feat: add revalidate and pub key to fetch
This commit is contained in:
parent
2f4a6d2177
commit
0d4c7e33fc
@ -20,6 +20,8 @@ import {
|
||||
} from './types';
|
||||
|
||||
const ENDPOINT = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_API;
|
||||
const MEDUSA_API_KEY = process.env.MEDUSA_API_KEY ?? '';
|
||||
const REVALIDATE_WINDOW = parseInt(process.env.REVALIDATE_WINDOW ?? `${60 * 15}`); // 15 minutes
|
||||
|
||||
export default async function medusaRequest(
|
||||
method: string,
|
||||
@ -29,8 +31,10 @@ export default async function medusaRequest(
|
||||
const options: RequestInit = {
|
||||
method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
'Content-Type': 'application/json',
|
||||
'x-publishable-key': MEDUSA_API_KEY
|
||||
},
|
||||
next: { revalidate: REVALIDATE_WINDOW }
|
||||
};
|
||||
|
||||
if (payload) {
|
||||
@ -244,26 +248,6 @@ const reshapeProductVariant = (
|
||||
};
|
||||
};
|
||||
|
||||
const reshapeCollection = (collection: MedusaProductCollection): ProductCollection => {
|
||||
const description = collection.description || collection.metadata?.description?.toString() || '';
|
||||
const seo = {
|
||||
title: collection?.metadata?.seo_title?.toString() || collection.title || '',
|
||||
description: collection?.metadata?.seo_description?.toString() || collection.description || ''
|
||||
};
|
||||
const path = `/${collection.handle}`;
|
||||
const updatedAt = collection.updated_at;
|
||||
const title = collection.name;
|
||||
|
||||
return {
|
||||
...collection,
|
||||
description,
|
||||
seo,
|
||||
title,
|
||||
path,
|
||||
updatedAt
|
||||
};
|
||||
};
|
||||
|
||||
const reshapeCategory = (category: ProductCategory): ProductCollection => {
|
||||
const description = category.description || category.metadata?.description?.toString() || '';
|
||||
const seo = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user