api 설정 분리

This commit is contained in:
2025-08-27 13:06:13 +09:00
parent ab84ef0d0e
commit ea3ec7de3b
5 changed files with 19 additions and 12 deletions

View File

@@ -15,7 +15,7 @@ export const useApi = <T>(
const method = options.method ? options.method.toUpperCase() : 'GET'
return useFetch<T>(() => `${config.public.apiBase}${path}`, {
return useFetch<T>(() => `${config.public.apiBase}${config.public.contextPath}${path}`, {
method: method as any, // 타입 강제 우회
body: options.body,
query: options.query,

View File

@@ -37,7 +37,8 @@ export default defineNuxtConfig({
},
runtimeConfig: {
public: {
apiBase: 'http://localhost'
apiBase: process.env.API_BASE || 'http://localhost',
contextPath: process.env.CONTEXT_PATH || '/service',
}
},
typescript: {

View File

@@ -16,13 +16,6 @@ export const useUserStore = defineStore("user", () => {
role: string
lastLoginAt: string
}
interface LoginResponse {
code: number
message: string
description: string
data: LoginData
}
// 게터
const isAdmin = computed(() => user.value?.role === "admin");
@@ -32,14 +25,14 @@ export const useUserStore = defineStore("user", () => {
try {
// 실제 API 호출로 대체할 수 있습니다
const {data, error: _error } = await useApi<LoginResponse>('/service/login', {
const {data, error: _error } = await useApi<ApiResponse<LoginData>>('/login', {
method: 'post',
body: { userId, password }
})
let mockUser;
if(data && data.value && data.value.code === 200){
if(data && data.value && data.value.success){
mockUser = data.value.data;
}else{
throw new Error("아이디 또는 비밀번호가 올바르지 않습니다.");

13
types/common.ts Normal file
View File

@@ -0,0 +1,13 @@
// types/common.ts
declare global {
interface ApiResponse<T> {
success: boolean
code: number
message: string
description: string
data: T
}
}
export {}

View File

@@ -5,5 +5,5 @@ declare module 'vue3-tui-grid' {
export default TuiGrid;
export type TuiGridElement = any;
export type GridEvent = any;
}
}