Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

api.ts

25 lines617 Bytes

1import { environmentManager } from '@tanstack/react-query'
2​
3function getBaseURL() {
4 if (!environmentManager.isServer()) {
5 return ''
6 }
7 if (process.env.VERCEL_URL) {
8 return `https://${process.env.VERCEL_URL}`
9 }
10 return 'http://localhost:3000'
12const baseUrl = getBaseURL()
13​
14export const waitAPI = {
15 getWait: async (wait: number): Promise<string> => {
16 const path = `/api/wait?wait=${wait}`
17 const url = baseUrl + path
18​
19 const response = await fetch(url, {
20 cache: 'no-store',
21 })
22 if (!response.ok) throw new Error('Failed to fetch data')
23 return await response.json()
24 },