This commit is contained in:
Kristian Duda 2024-06-28 14:28:34 +02:00
parent 9b9f9496c3
commit be65e581f3
2 changed files with 23 additions and 1 deletions

View File

@ -3,4 +3,5 @@ TWITTER_CREATOR="@vercel"
TWITTER_SITE="https://nextjs.org/commerce"
SITE_NAME="Next.js Commerce"
CMS_URL="http://localhost:3000"
APP_URL="http://localhost:3000"
CMS_URL="http://localhost:8000"

21
app/api/checkout/route.ts Normal file
View File

@ -0,0 +1,21 @@
import { ajax } from 'lib/shopify/ajax';
import { cookies } from 'next/headers';
import { NextResponse } from 'next/server';
export async function GET(): Promise<NextResponse> {
const cartId = cookies().get('cartId')?.value;
if (!cartId) {
return NextResponse.json({ message: 'Cart not found.' }, { status: 404 });
}
try {
const session = await ajax<any>('POST', `${process.env.CMS_URL}/api/carts/${cartId}/checkout`, {
url: process.env.APP_URL
});
return NextResponse.redirect(session.url, 303);
} catch (err: any) {
return NextResponse.json({ message: err.message }, { status: err.statusCode });
}
}