diff --git a/.env.example b/.env.example index f30e51a65..5881494df 100644 --- a/.env.example +++ b/.env.example @@ -2,8 +2,5 @@ COMPANY_NAME="Vercel Inc." TWITTER_CREATOR="@vercel" TWITTER_SITE="https://nextjs.org/commerce" SITE_NAME="Next.js Commerce" -# SHOPIFY_REVALIDATION_SECRET="" -# SHOPIFY_STOREFRONT_ACCESS_TOKEN="" -# SHOPIFY_STORE_DOMAIN="[your-shopify-store-subdomain].myshopify.com" CMS_URL="http://localhost:3000" diff --git a/app/api/revalidate/route.ts b/app/api/revalidate/route.ts deleted file mode 100644 index 4ecc0b45d..000000000 --- a/app/api/revalidate/route.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { revalidate } from 'lib/shopify'; -import { NextRequest, NextResponse } from 'next/server'; - -export async function POST(req: NextRequest): Promise { - return revalidate(req); -} diff --git a/app/opengraph-image.tsx b/app/opengraph-image.tsx index 23762cbdd..fb317b2dc 100644 --- a/app/opengraph-image.tsx +++ b/app/opengraph-image.tsx @@ -3,5 +3,6 @@ import OpengraphImage from 'components/opengraph-image'; export const runtime = 'edge'; export default async function Image() { - return await OpengraphImage(); + const title = process.env.SITE_NAME || 'Payload Store'; + return await OpengraphImage({ title }); } diff --git a/lib/shopify/index.ts b/lib/shopify/index.ts index b4c4916d5..90397c93b 100644 --- a/lib/shopify/index.ts +++ b/lib/shopify/index.ts @@ -1,4 +1,3 @@ -import { TAGS } from 'lib/constants'; import { AjaxError } from 'lib/shopify/ajax'; import { Where, create, find, findByID, update } from 'lib/shopify/payload'; import { @@ -8,9 +7,6 @@ import { Option as PayloadOption, Product as PayloadProduct } from 'lib/shopify/payload-types'; -import { revalidateTag } from 'next/cache'; -import { headers } from 'next/headers'; -import { NextRequest, NextResponse } from 'next/server'; import { Cart, CartItem, @@ -378,35 +374,3 @@ export async function getProducts({ const products = await find('products', { where }); return products.docs.map(reshapeProduct); } - -// This is called from `app/api/revalidate.ts` so providers can control revalidation logic. -export async function revalidate(req: NextRequest): Promise { - // We always need to respond with a 200 status code to Shopify, - // otherwise it will continue to retry the request. - const collectionWebhooks = ['collections/create', 'collections/delete', 'collections/update']; - const productWebhooks = ['products/create', 'products/delete', 'products/update']; - const topic = headers().get('x-shopify-topic') || 'unknown'; - const secret = req.nextUrl.searchParams.get('secret'); - const isCollectionUpdate = collectionWebhooks.includes(topic); - const isProductUpdate = productWebhooks.includes(topic); - - if (!secret || secret !== process.env.SHOPIFY_REVALIDATION_SECRET) { - console.error('Invalid revalidation secret.'); - return NextResponse.json({ status: 200 }); - } - - if (!isCollectionUpdate && !isProductUpdate) { - // We don't need to revalidate anything for any other topics. - return NextResponse.json({ status: 200 }); - } - - if (isCollectionUpdate) { - revalidateTag(TAGS.collections); - } - - if (isProductUpdate) { - revalidateTag(TAGS.products); - } - - return NextResponse.json({ status: 200, revalidated: true, now: Date.now() }); -}