하수재이용통계
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
"use client";
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
|
||||
|
||||
return (
|
||||
{children}
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
"use client";
|
||||
import { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
|
||||
export default function HasuStatPage() {
|
||||
const [status, setStatus] = useState<string>("checking");
|
||||
|
||||
useEffect(() => {
|
||||
let didCancel = false;
|
||||
|
||||
async function checkAndRedirect() {
|
||||
try {
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), 3000);
|
||||
|
||||
const res = await fetch(`/api/client-ip`, { signal: controller.signal });
|
||||
clearTimeout(timeout);
|
||||
|
||||
if (!res.ok) throw new Error("no-ip");
|
||||
const data = await res.json();
|
||||
const ip: string = data?.ip || "";
|
||||
console.log("Client IP:", ip);
|
||||
if (didCancel) return;
|
||||
|
||||
const is10 = /^10\./.test(ip);
|
||||
setStatus(is10 ? "redirect-internal" : "redirect-root");
|
||||
|
||||
// // Use location.replace so user can't go back to this page
|
||||
// if (is10) {
|
||||
// // redirect to internal IP
|
||||
// // window.location.replace("http://10.101.163.102:8888/cms/lay1/WS10000014/program.do");
|
||||
// window.open('http://10.101.163.102:8888/cms/lay1/WS10000014/program.do', '_blank');
|
||||
// } else {
|
||||
// //window.location.replace("https://www.hasudoinfo.or.kr/cms/lay1/WS10000014/program.do");
|
||||
// window.open('https://www.hasudoinfo.or.kr/cms/lay1/WS10000014/program.do', '_blank');
|
||||
// }
|
||||
} catch {
|
||||
// If anything fails, fall back to root
|
||||
if (!didCancel) {
|
||||
setStatus("error-fallback");
|
||||
window.location.replace("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkAndRedirect();
|
||||
|
||||
return () => {
|
||||
didCancel = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div style={{padding:20,fontFamily:'Noto Sans KR, sans-serif'}}>
|
||||
{status === "checking" && <div>접속 IP 확인 중...</div>}
|
||||
{status === "redirect-internal" && <div>내부망으로 이동합니다...</div>}
|
||||
{status === "redirect-root" && <div>외부에서 접속하여 루트로 이동합니다...</div>}
|
||||
{status === "error-fallback" && (
|
||||
<div>
|
||||
문제가 발생하여 루트로 이동합니다. 이동하지 않으면 <Link href="/">여기</Link>를 클릭하세요.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const headers = request.headers;
|
||||
// Prefer x-forwarded-for (may be comma separated list)
|
||||
const xff = headers.get('x-forwarded-for') ?? headers.get('x-real-ip') ?? '';
|
||||
let ip = '';
|
||||
if (xff && xff.length > 0) {
|
||||
ip = String(xff).split(',')[0].trim();
|
||||
}
|
||||
|
||||
return NextResponse.json({ ip });
|
||||
}
|
||||
Reference in New Issue
Block a user