boring.tools-poc/apps/app/src/utils/queryFetch.ts
Lars Hampe 975d2e1d58
All checks were successful
Build and Push Docker Image / tests (push) Successful in 29s
Build and Push Docker Image / build (push) Successful in 1m46s
feat(app): use PROD env var instead of NODE_ENV
2024-10-03 21:36:47 +02:00

25 lines
491 B
TypeScript

import axios from 'axios'
type Fetch = {
path: string
method: 'get' | 'post' | 'put' | 'delete'
data?: unknown
token?: string | null
}
const url = import.meta.env.PROD
? 'https://api.boring.tools'
: 'http://localhost:3000'
export const queryFetch = async ({ path, method, data, token }: Fetch) => {
const response = await axios({
method,
url: `${url}/v1/${path}`,
data,
headers: {
Authorization: `Bearer ${token}`,
},
})
return response.data
}