260312_01_ENH: Error 페이지 및 Redirect 페이지 구현
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { clientEnv } from "@/lib/env.client";
|
||||
import {DEFAULT_API_TIMEOUT_MS} from "@/const/commonConst";
|
||||
|
||||
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
||||
|
||||
@@ -105,7 +106,7 @@ const isJsonContentType = (ctype: string) => {
|
||||
export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {}) => {
|
||||
const {
|
||||
getToken,
|
||||
defaultTimeoutMs = 60_000,
|
||||
defaultTimeoutMs = DEFAULT_API_TIMEOUT_MS,
|
||||
defaultHeaders = { "content-type": "application/json" },
|
||||
setErrorMessage,
|
||||
} = opts;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
import type {NextRequest} from "next/server";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
@@ -99,4 +100,33 @@ export const formatKst = (
|
||||
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`;
|
||||
};
|
||||
|
||||
export const isBlank = (v?: string | null) => !v || v.trim().length === 0;
|
||||
export const isBlank = (v?: string | null) => !v || v.trim().length === 0;
|
||||
|
||||
export const getClientIp = (req: NextRequest): string | null => {
|
||||
const h = req.headers;
|
||||
|
||||
// 가장 흔한 케이스: 프록시/호스팅이 넣어줌
|
||||
const xff = h.get("x-forwarded-for");
|
||||
if (xff) {
|
||||
// "client, proxy1, proxy2" 형태. 보통 첫 번째가 client IP로 쓰이지만,
|
||||
// 프록시가 헤더를 덮어쓰지 않고 append만 하는 환경이면 spoof 가능성 있음.
|
||||
return xff.split(",")[0].trim();
|
||||
}
|
||||
|
||||
// 일부 인프라/프록시에서 쓰는 헤더들
|
||||
const xRealIp = h.get("x-real-ip");
|
||||
if (xRealIp) return xRealIp.trim();
|
||||
|
||||
// (Cloudflare 등) 사용 환경이면
|
||||
const cf = h.get("cf-connecting-ip");
|
||||
if (cf) return cf.trim();
|
||||
|
||||
// RFC 7239 Forwarded: for=1.2.3.4;proto=https;by=...
|
||||
const forwarded = h.get("forwarded");
|
||||
if (forwarded) {
|
||||
const m = forwarded.match(/for="?([^;,\s"]+)"?/i);
|
||||
if (m?.[1]) return m[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user