260312_01_ENH: Error 페이지 및 Redirect 페이지 구현
This commit is contained in:
@@ -45,7 +45,7 @@ const LoginPage = () => {
|
||||
const err = apiError(e);
|
||||
if (err.status === 401 || err.status === 403) setError("아이디 또는 비밀번호를 다시 확인해주세요.");
|
||||
else if (err.code === NONE_HTTP_ERROR) setError("알 수 없는 오류가 발생했습니다. 잠시 후 다시 시도해주세요.");
|
||||
else setError(`로그인에 실패했습니다. (status: ${err.status})`);
|
||||
else setError(`로그인에 실패했습니다. (${err.message})`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
37
src/app/(pages)/redirect/[slug]/page.tsx
Normal file
37
src/app/(pages)/redirect/[slug]/page.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import RedirectLanding from "@/components/external/RedirectLanding";
|
||||
import {notFound} from "next/navigation";
|
||||
import {ALLOW_REDIRECT} from "@/const/commonConst";
|
||||
import {RedirectSlug} from "@/types/common";
|
||||
|
||||
type redirectPageProps = {
|
||||
params: Promise<{ slug: string }>;
|
||||
searchParams?: Promise<Record<string, string | string[] | undefined>>;
|
||||
}
|
||||
|
||||
const toRedirectSlug = (slug: string): RedirectSlug | null => {
|
||||
return ALLOW_REDIRECT.has(slug.toLowerCase()) ? (slug.toLowerCase() as RedirectSlug) : null;
|
||||
}
|
||||
|
||||
const redirectPage = async ({
|
||||
params,
|
||||
searchParams,
|
||||
}: redirectPageProps) => {
|
||||
const { slug } = await params;
|
||||
const sp = searchParams ? await searchParams : undefined;
|
||||
|
||||
//미들 웨어에서 처리
|
||||
console.log(sp);
|
||||
|
||||
const redirectSlug = toRedirectSlug(slug);
|
||||
|
||||
console.log(redirectSlug);
|
||||
|
||||
|
||||
if (!redirectSlug) notFound();
|
||||
|
||||
return (
|
||||
<RedirectLanding redirectSlug={redirectSlug} />
|
||||
)
|
||||
}
|
||||
|
||||
export default redirectPage;
|
||||
35
src/app/(pages)/redirect/error/page.tsx
Normal file
35
src/app/(pages)/redirect/error/page.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import ErrorPage from "@/components/external/Error";
|
||||
import {ErrorCode} from "@/types/common";
|
||||
|
||||
function toErrorCode(raw: string | undefined): ErrorCode {
|
||||
if (raw === "500") return "500";
|
||||
// fetch_error, 기타 알 수 없는 코드 → 500으로 처리
|
||||
if (raw && raw !== "404") return "500";
|
||||
return "404";
|
||||
}
|
||||
|
||||
type RedirectErrorPageProps = {
|
||||
searchParams: Promise<Record<string, string | string[] | undefined>>;
|
||||
};
|
||||
|
||||
const RedirectErrorPage = async ({ searchParams }: RedirectErrorPageProps) => {
|
||||
const sp = await searchParams;
|
||||
|
||||
console.log(sp)
|
||||
|
||||
const code = toErrorCode(sp.code as string | undefined);
|
||||
const sid = (sp.sid as string | undefined) ?? "";
|
||||
|
||||
return (
|
||||
<ErrorPage
|
||||
code={code}
|
||||
errorDescription={
|
||||
sid
|
||||
? `오류가 발생했습니다. 관리자에게 문의할 경우 아래 코드를 전달해 주세요.\n리스트 ID : ${sid}`
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default RedirectErrorPage
|
||||
43
src/app/api/external/[[...slug]]/route.ts
vendored
43
src/app/api/external/[[...slug]]/route.ts
vendored
@@ -1 +1,42 @@
|
||||
//외부 설문에 뎐동 되는 API
|
||||
//외부 설문에 뎐동 되는 API
|
||||
|
||||
import {NextRequest, NextResponse} from "next/server";
|
||||
import {RouteContext} from "@/types/common";
|
||||
import {createContactApi} from "@/lib/server-api";
|
||||
import {errorToResponse} from "@/lib/http-util";
|
||||
import {getClientIp} from "@/lib/utils";
|
||||
|
||||
export const POST = async (req: NextRequest, context: RouteContext) => {
|
||||
try {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const {slug = []} = await context.params;
|
||||
const [action] = slug;
|
||||
|
||||
console.log(slug)
|
||||
const sid = (searchParams.get("sid") ?? "").trim();
|
||||
const allowAction = ["start", "complete", "screen", "quota"]
|
||||
if(slug.length === 1 && allowAction.includes(action.toLowerCase()) && sid.length > 0){
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
const pathname = req.nextUrl.pathname;
|
||||
const h = req.headers;
|
||||
const log = {
|
||||
remoteAddr: h.get("x-orig-ip") || getClientIp(req),
|
||||
uri: h.get("x-orig-uri") || pathname,
|
||||
url: h.get("x-orig-url") || req.url,
|
||||
userAgent: h.get("x-orig-user-agent") || h.get("user-agent"),
|
||||
referer: h.get("x-orig-referer") || h.get("referer"),
|
||||
origin: h.get("x-orig-origin") || h.get("origin"),
|
||||
xForwardedFor: h.get("x-forwarded-for"),
|
||||
forwarded: h.get("forwarded"),
|
||||
};
|
||||
|
||||
//Todo 수정 필요
|
||||
return new NextResponse(null, { status: 204 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
};
|
||||
9
src/app/not-found.tsx
Normal file
9
src/app/not-found.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import ErrorPage from "@/components/external/Error";
|
||||
|
||||
const NotFound = () => {
|
||||
return (
|
||||
<ErrorPage code="404" />
|
||||
)
|
||||
}
|
||||
|
||||
export default NotFound
|
||||
Reference in New Issue
Block a user