Catalin Pinte c75b0fc001
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
2022-10-30 13:41:21 -05:00

26 lines
538 B
TypeScript

import { Fetcher } from '@vercel/commerce/utils/types'
import { API_URL } from './const'
import { getToken, handleFetchResponse } from './utils'
const fetcher: Fetcher = async ({
url = API_URL,
method = 'POST',
variables,
query,
}) => {
const token = getToken()
return handleFetchResponse(
await fetch(url!, {
method,
body: JSON.stringify({ query, variables }),
headers: {
Authorization: `JWT ${token}`,
'Content-Type': 'application/json',
},
})
)
}
export default fetcher