1
0
mirror of https://github.com/vercel/commerce.git synced 2025-04-01 17:55:54 +00:00
2021-02-04 17:18:33 +02:00

24 lines
583 B
TypeScript

import isAllowedMethod from '../utils/is-allowed-method'
import createApiHandler, {
ShopifyApiHandler,
} from '../utils/create-api-handler'
import { SHOPIFY_CHECKOUT_URL_COOKIE } from '@framework/const'
const METHODS = ['GET']
const checkoutApi: ShopifyApiHandler<any> = async (req, res) => {
if (!isAllowedMethod(req, res, METHODS)) return
const { cookies } = req
const checkoutUrl = cookies[SHOPIFY_CHECKOUT_URL_COOKIE]
if (checkoutUrl) {
res.redirect(checkoutUrl)
} else {
res.redirect('/cart')
}
}
export default createApiHandler(checkoutApi, {}, {})