mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
Dynamic API routes (#836)
* Add dynamic API endpoints * Add missing dependency * Update api handlers * Updates * Fix build errors * Update package.json * Add checkout endpoint parser & update errors * Update tsconfig.json * Update cart.ts * Update parser * Update errors.ts * Update errors.ts * Move to Edge runtime * Revert to local * Fix switchable runtimes * Make nodejs default runtime * Update pnpm-lock.yaml * Update handlers * Fix build errors * Change headers
This commit is contained in:
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
@@ -2,11 +2,9 @@ import type { CheckoutEndpoint } from '.'
|
||||
|
||||
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
||||
req: _request,
|
||||
res: response,
|
||||
config: _config,
|
||||
}) => {
|
||||
try {
|
||||
const html = `
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@@ -28,17 +26,11 @@ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
||||
</html>
|
||||
`
|
||||
|
||||
response.status(200)
|
||||
response.setHeader('Content-Type', 'text/html')
|
||||
response.write(html)
|
||||
response.end()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
|
||||
const message = 'An unexpected error ocurred'
|
||||
|
||||
response.status(500).json({ data: null, errors: [{ message }] })
|
||||
}
|
||||
return new Response(html, {
|
||||
headers: {
|
||||
'content-type': 'text/html',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export default getCheckout
|
||||
|
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
11
packages/spree/src/api/endpoints/index.ts
Normal file
11
packages/spree/src/api/endpoints/index.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { SpreeApiProvider, SpreeApi } from '..'
|
||||
import createEndpoints from '@vercel/commerce/api/endpoints'
|
||||
import checkout from './checkout'
|
||||
|
||||
const endpoints = {
|
||||
checkout,
|
||||
}
|
||||
|
||||
export default function spreeAPI(commerce: SpreeApi) {
|
||||
return createEndpoints<SpreeApiProvider>(commerce, endpoints)
|
||||
}
|
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
@@ -9,7 +9,6 @@ import { GraphQLFetcher, GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import createCustomizedFetchFetcher, {
|
||||
fetchResponseKey,
|
||||
} from '../../utils/create-customized-fetch-fetcher'
|
||||
import fetch, { Request } from 'node-fetch'
|
||||
import type { SpreeSdkResponseWithRawResponse } from '../../types'
|
||||
import prettyPrintSpreeSdkErrors from '../../utils/pretty-print-spree-sdk-errors'
|
||||
|
||||
|
@@ -5,8 +5,7 @@ import type {
|
||||
JsonApiSingleResponse,
|
||||
} from '@spree/storefront-api-v2-sdk/types/interfaces/JsonApi'
|
||||
import type { ResultResponse } from '@spree/storefront-api-v2-sdk/types/interfaces/ResultResponse'
|
||||
import type { Response } from '@vercel/fetch'
|
||||
import type { ProductOption, Product } from '@vercel/commerce/types/product'
|
||||
import type { ProductOption } from '@vercel/commerce/types/product'
|
||||
import type {
|
||||
Wishlist as CoreWishlist,
|
||||
WishlistItemBody as CoreWishlistItemBody,
|
||||
|
Reference in New Issue
Block a user