2025-08-08 13:11:33 +09:00
|
|
|
import { useFetch, useRuntimeConfig, useCookie } from '#imports'
|
|
|
|
|
|
|
|
export const useApi = <T>(
|
|
|
|
path: string,
|
|
|
|
options: {
|
|
|
|
method?: 'get' | 'post' | 'put' | 'delete'
|
|
|
|
body?: any
|
|
|
|
query?: Record<string, any>
|
|
|
|
headers?: HeadersInit
|
|
|
|
server?: boolean // ← 이 줄 추가!
|
|
|
|
} = {}
|
|
|
|
) => {
|
|
|
|
const config = useRuntimeConfig()
|
|
|
|
const token = useCookie('token')
|
|
|
|
|
|
|
|
const method = options.method ? options.method.toUpperCase() : 'GET'
|
|
|
|
|
2025-08-27 13:06:13 +09:00
|
|
|
return useFetch<T>(() => `${config.public.apiBase}${config.public.contextPath}${path}`, {
|
2025-08-08 13:11:33 +09:00
|
|
|
method: method as any, // 타입 강제 우회
|
|
|
|
body: options.body,
|
|
|
|
query: options.query,
|
|
|
|
headers: {
|
|
|
|
Authorization: token.value ? `Bearer ${token.value}` : '',
|
|
|
|
...options.headers
|
|
|
|
},
|
|
|
|
server: options.server // ← 이 줄 추가!
|
|
|
|
})
|
|
|
|
}
|