mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 15:06:59 +00:00
Fix build errors
This commit is contained in:
parent
3fd24810f9
commit
c27328f853
@ -64,36 +64,38 @@ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make the embedded checkout work too!
|
// TODO: make the embedded checkout work too!
|
||||||
const html = `
|
// const html = `
|
||||||
<!DOCTYPE html>
|
// <!DOCTYPE html>
|
||||||
<html lang="en">
|
// <html lang="en">
|
||||||
<head>
|
// <head>
|
||||||
<meta charset="UTF-8">
|
// <meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
// <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Checkout</title>
|
// <title>Checkout</title>
|
||||||
<script src="https://checkout-sdk.bigcommerce.com/v1/loader.js"></script>
|
// <script src="https://checkout-sdk.bigcommerce.com/v1/loader.js"></script>
|
||||||
<script>
|
// <script>
|
||||||
window.onload = function() {
|
// window.onload = function() {
|
||||||
checkoutKitLoader.load('checkout-sdk').then(function (service) {
|
// checkoutKitLoader.load('checkout-sdk').then(function (service) {
|
||||||
service.embedCheckout({
|
// service.embedCheckout({
|
||||||
containerId: 'checkout',
|
// containerId: 'checkout',
|
||||||
url: '${data.embedded_checkout_url}'
|
// url: '${data.embedded_checkout_url}'
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
</script>
|
// </script>
|
||||||
</head>
|
// </head>
|
||||||
<body>
|
// <body>
|
||||||
<div id="checkout"></div>
|
// <div id="checkout"></div>
|
||||||
</body>
|
// </body>
|
||||||
</html>
|
// </html>
|
||||||
`
|
// `
|
||||||
|
|
||||||
return new Response(html, {
|
// return new Response(html, {
|
||||||
headers: {
|
// headers: {
|
||||||
'Content-Type': 'text/html',
|
// 'Content-Type': 'text/html',
|
||||||
},
|
// },
|
||||||
})
|
// })
|
||||||
|
|
||||||
|
return { data: null }
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getCheckout
|
export default getCheckout
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import type { NextApiRequest } from 'next'
|
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import type { ZodSchema } from 'zod'
|
import type { ZodSchema } from 'zod'
|
||||||
import type { APIResponse } from './types'
|
import type { APIResponse } from './types'
|
||||||
|
|
||||||
@ -52,15 +52,17 @@ export const transformRequest = (req: NextApiRequest, path: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const transformHeaders = (
|
export const transformHeaders = (
|
||||||
headers?: Record<string, string | number | string[]>
|
headers?: Record<string, string | number | string[]> | Headers
|
||||||
) =>
|
) => {
|
||||||
headers
|
if (headers instanceof Headers) {
|
||||||
? Object.entries(headers).reduce((acc, [key, value]) => {
|
return headers
|
||||||
if (Array.isArray(value)) {
|
}
|
||||||
value.forEach((v) => acc.append(key, v))
|
|
||||||
} else {
|
const newHeaders = new Headers()
|
||||||
acc.append(key, `${value}`)
|
|
||||||
}
|
Object.entries(headers || {}).forEach(([key, value]) => {
|
||||||
return acc
|
newHeaders.append(key, value as string)
|
||||||
}, new Headers())
|
})
|
||||||
: new Headers()
|
|
||||||
|
return newHeaders
|
||||||
|
}
|
||||||
|
@ -45,17 +45,22 @@ export default function nodeHandler<P extends APIProvider>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const output = await handlers[path](transformRequest(req, path))
|
const output = await handlers[path](transformRequest(req, path))
|
||||||
|
|
||||||
if (output instanceof Response) {
|
|
||||||
return res.end(output.body)
|
|
||||||
}
|
|
||||||
|
|
||||||
const { status, errors, data, redirectTo, headers } = output
|
const { status, errors, data, redirectTo, headers } = output
|
||||||
|
|
||||||
if (headers) {
|
if (headers) {
|
||||||
Object.entries(headers).forEach(([key, value]) => {
|
if (headers instanceof Headers) {
|
||||||
res.setHeader(key, value)
|
headers.forEach((value, key) => {
|
||||||
})
|
res.setHeader(key, value)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Object.entries(headers).forEach(([key, value]) => {
|
||||||
|
res.setHeader(key, value)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (output instanceof Response) {
|
||||||
|
return res.end(output.body)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redirectTo) {
|
if (redirectTo) {
|
||||||
|
@ -7,7 +7,7 @@ export type APIResponse<Data = any> = {
|
|||||||
data?: Data
|
data?: Data
|
||||||
errors?: ErrorData[]
|
errors?: ErrorData[]
|
||||||
status?: number
|
status?: number
|
||||||
headers?: Record<string, number | string | string[]>
|
headers?: Record<string, number | string | string[]> | Headers
|
||||||
/**
|
/**
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @example redirectTo: '/cart'
|
* @example redirectTo: '/cart'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user