mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
Setup fetchers
This commit is contained in:
@@ -1,7 +1,17 @@
|
||||
import { Fetcher } from '@commerce/utils/types'
|
||||
|
||||
export const fetcher: Fetcher = async () => {
|
||||
throw new Error(
|
||||
'Client side fetching has not been implemented yet, try to fetch from server side.'
|
||||
)
|
||||
const clientFetcher: Fetcher = async ({ method, url, body }) => {
|
||||
const response = await fetch(url!, {
|
||||
method,
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((response) => response.data)
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
export default clientFetcher
|
||||
|
Reference in New Issue
Block a user