251210_01_ENH : 프로젝트 수정, 에디터 구현중
This commit is contained in:
@@ -7,5 +7,8 @@ const required = (name: string) => {
|
||||
export const serverEnv = {
|
||||
ENV: required("ENV"),
|
||||
API_CONTACT_SERVER: required("API_CONTACT_SERVER"),
|
||||
API_INTRANET_SERVER: required("API_INTRANET_SERVER"),
|
||||
API_KART_SERVER: required("API_KART_SERVER"),
|
||||
KART_API_KEY: required("KART_API_KEY"),
|
||||
// 다른 서버 전용 env들 추가 가능
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import {NextResponse} from "next/server";
|
||||
import {HttpError} from "@/lib/http-client";
|
||||
import {clientEnv} from "@/lib/env.client";
|
||||
import commonConst from "@/config/commonConst";
|
||||
import {NONE_HTTP_ERROR, UNKNOWN_HTTP_ERROR} from "@/const/commonConst";
|
||||
|
||||
export type ApiError = {
|
||||
status: number
|
||||
@@ -26,7 +26,7 @@ const isDev = clientEnv.ENV !== "prod"
|
||||
export const apiError = (e: unknown): ApiError => {
|
||||
if (e instanceof HttpError) {
|
||||
const d = e.data as any
|
||||
const code = typeof d?.code === "string" ? d.code : commonConst.unknownHttpError
|
||||
const code = typeof d?.code === "string" ? d.code : UNKNOWN_HTTP_ERROR
|
||||
const message =
|
||||
(typeof d?.detail === "string" && d.detail) ||
|
||||
(typeof d?.message === "string" && d.message) ||
|
||||
@@ -48,5 +48,5 @@ export const apiError = (e: unknown): ApiError => {
|
||||
}
|
||||
|
||||
if (isDev) console.error("[NON-HTTP ERROR]", e)
|
||||
return { status: 500, code: commonConst.noneHttpError, message: "저장에 실패했습니다." }
|
||||
return { status: 500, code: NONE_HTTP_ERROR, message: "저장에 실패했습니다." }
|
||||
}
|
||||
|
||||
@@ -2,15 +2,29 @@ import { cookies } from "next/headers";
|
||||
import { createHttpClient } from "@/lib/http-client";
|
||||
import { serverEnv } from "@/lib/env.server";
|
||||
|
||||
const createServerApi = async (rootUrl: string) => {
|
||||
const createServerApi = async (rootUrl: string, defaultHeaders?: Record<string, string>) => {
|
||||
const cookieStore = await cookies();
|
||||
const accessToken = cookieStore.get("access_token")?.value ?? null;
|
||||
|
||||
return createHttpClient(rootUrl, {
|
||||
getToken: () => accessToken, // 이미 위에서 읽은 값만 참조
|
||||
defaultHeaders: {
|
||||
"content-type": "application/json",
|
||||
...(defaultHeaders ?? {}),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const createContactApi = () => {
|
||||
return createServerApi(serverEnv.API_CONTACT_SERVER);
|
||||
}
|
||||
}
|
||||
|
||||
export const createIntranetApi = () => {
|
||||
return createServerApi(serverEnv.API_INTRANET_SERVER);
|
||||
}
|
||||
|
||||
export const createKartApi = () => {
|
||||
return createServerApi(serverEnv.API_KART_SERVER, {
|
||||
"X-API-Key": serverEnv.KART_API_KEY,
|
||||
});
|
||||
};
|
||||
@@ -5,6 +5,21 @@ export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
|
||||
export function getKeyByValue<
|
||||
const T extends Record<PropertyKey, string>
|
||||
>(map: T, value: T[keyof T]) {
|
||||
const entry = Object.entries(map).find(([, v]) => v === value);
|
||||
return entry ? (entry[0] as keyof T) : undefined;
|
||||
}
|
||||
|
||||
export function getNumberKeyByValue(
|
||||
map: Record<number, string>,
|
||||
value: string
|
||||
): number | undefined {
|
||||
const entry = Object.entries(map).find(([, v]) => v === value);
|
||||
return entry ? Number(entry[0]) : undefined;
|
||||
}
|
||||
|
||||
export function buildUrlWithParams(
|
||||
targetPath: string,
|
||||
from: Record<string, string | string[] | undefined>,
|
||||
|
||||
Reference in New Issue
Block a user