api 설정 분리
This commit is contained in:
@@ -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,
|
||||
|
@@ -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: {
|
||||
|
@@ -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
13
types/common.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
// types/common.ts
|
||||
declare global {
|
||||
interface ApiResponse<T> {
|
||||
success: boolean
|
||||
code: number
|
||||
message: string
|
||||
description: string
|
||||
data: T
|
||||
}
|
||||
}
|
||||
|
||||
export {}
|
||||
|
2
types/vue3-tui-grid.d.ts
vendored
2
types/vue3-tui-grid.d.ts
vendored
@@ -5,5 +5,5 @@ declare module 'vue3-tui-grid' {
|
||||
export default TuiGrid;
|
||||
export type TuiGridElement = any;
|
||||
export type GridEvent = any;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user