mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 12:11:23 +00:00
.vscode
assets
components
config
framework
bigcommerce
commerce
local
saleor
shopify
swell
api
cart
catalog
customers
endpoints
catalog
checkout
index.ts
cart.ts
customer.ts
login.ts
logout.ts
signup.ts
wishlist.ts
operations
utils
wishlist
customer.ts
index.ts
auth
cart
customer
product
types
utils
wishlist
.env.template
commerce.config.json
const.ts
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
types.ts
vendure
lib
pages
public
.editorconfig
.env.template
.gitignore
.prettierignore
.prettierrc
README.md
codegen.bigcommerce.json
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
swell-js.d.ts
tailwind.config.js
tsconfig.json
yarn.lock
* fix update cart item * update types * update checkout * update get-page, cleanup types * revert change to incorrect file * cleanup Co-authored-by: Greg Hoskin <greghoskin@Gregs-MacBook-Pro.local>
31 lines
848 B
TypeScript
31 lines
848 B
TypeScript
import { CommerceAPI, createEndpoint, GetAPISchema } from '@commerce/api'
|
|
import { CheckoutSchema } from '@commerce/types/checkout'
|
|
import { SWELL_CHECKOUT_URL_COOKIE } from '../../../const'
|
|
import checkoutEndpoint from '@commerce/api/endpoints/checkout'
|
|
|
|
const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
|
|
req,
|
|
res,
|
|
config,
|
|
}) => {
|
|
const { cookies } = req
|
|
const checkoutUrl = cookies[SWELL_CHECKOUT_URL_COOKIE]
|
|
|
|
if (checkoutUrl) {
|
|
res.redirect(checkoutUrl)
|
|
} else {
|
|
res.redirect('/cart')
|
|
}
|
|
}
|
|
export const handlers: CheckoutEndpoint['handlers'] = { checkout }
|
|
|
|
export type CheckoutAPI = GetAPISchema<CommerceAPI, CheckoutSchema>
|
|
export type CheckoutEndpoint = CheckoutAPI['endpoint']
|
|
|
|
const checkoutApi = createEndpoint<CheckoutAPI>({
|
|
handler: checkoutEndpoint,
|
|
handlers,
|
|
})
|
|
|
|
export default checkoutApi
|