From cf88f723650e83508a5aeed58609fe35a51a3588 Mon Sep 17 00:00:00 2001 From: WooWan Date: Tue, 6 Aug 2024 02:30:32 +0900 Subject: [PATCH 1/5] =?UTF-8?q?remove:=20redirect=20=EB=A1=9C=EC=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- next.config.mjs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/next.config.mjs b/next.config.mjs index f1f038c..4678774 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,14 +1,4 @@ /** @type {import('next').NextConfig} */ -const nextConfig = { - redirects: async () => { - return [ - { - source: "/", - destination: "/ut", - permanent: true, - }, - ]; - }, -}; +const nextConfig = {}; export default nextConfig; From ad4c975c63211dd418c2f369ed894e9e405043c6 Mon Sep 17 00:00:00 2001 From: WooWan Date: Tue, 6 Aug 2024 02:30:51 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20middleware=EC=97=90=EC=84=9C=20wild?= =?UTF-8?q?card=20=EC=84=9C=EB=B8=8C=EB=8F=84=EB=A9=94=EC=9D=B8=20rewrite?= =?UTF-8?q?=EB=A1=9C=EC=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(playground)/pg/[subdomain]/page.tsx | 3 ++ src/middleware.ts | 31 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/app/(playground)/pg/[subdomain]/page.tsx create mode 100644 src/middleware.ts diff --git a/src/app/(playground)/pg/[subdomain]/page.tsx b/src/app/(playground)/pg/[subdomain]/page.tsx new file mode 100644 index 0000000..4721981 --- /dev/null +++ b/src/app/(playground)/pg/[subdomain]/page.tsx @@ -0,0 +1,3 @@ +export default function Page({ params }: { params: { subdomain: string } }) { + return
Subdomain: {params.subdomain}
; +} diff --git a/src/middleware.ts b/src/middleware.ts new file mode 100644 index 0000000..d940905 --- /dev/null +++ b/src/middleware.ts @@ -0,0 +1,31 @@ +import type { NextRequest } from "next/server"; +import { NextResponse } from "next/server"; + +export const config = { + matcher: ["/((?!api/|_next/|_static/|_vercel|[\\w-]+\\.\\w+).*)"], +}; + +export function middleware(request: NextRequest) { + const url = request.nextUrl; + const hostname = request.headers + .get("host")! + .replace(".localhost:3000", `.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}`); + const searchParams = request.nextUrl.searchParams.toString(); + + const path = `${url.pathname}${ + searchParams.length > 0 ? `?${searchParams}` : "" + }`; + + const subDomain = hostname.split(".")[0]; + + switch (true) { + case subDomain !== hostname: + console.log(`/pg/${subDomain}${path}`); + return NextResponse.rewrite( + new URL(`/pg/${subDomain}${path}`, request.url), + ); + + default: + return NextResponse.rewrite(new URL(`${path}`, request.url)); + } +} From af0197587278e44468ff7fbbae5d2b44314f27bf Mon Sep 17 00:00:00 2001 From: WooWan Date: Tue, 6 Aug 2024 19:37:36 +0900 Subject: [PATCH 3/5] =?UTF-8?q?chore:=20=ED=99=98=EA=B2=BD=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.template | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 6282d32..b245079 100644 --- a/.env.template +++ b/.env.template @@ -26,4 +26,6 @@ NAVER_REDIRECT_URI= ### @see https://developers.kakao.com/console/app/1102339/config/appKey KAKAO_MAP_BASE_URL= KAKAO_MAP_API_KEY= -DAUMCDN_POSTOCDE_URL= \ No newline at end of file +DAUMCDN_POSTOCDE_URL= + +ROOT_DOMAIN= \ No newline at end of file From e3b17bd78127b771aa85a85a5d1cc6902d6c513e Mon Sep 17 00:00:00 2001 From: WooWan Date: Tue, 6 Aug 2024 19:37:44 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=EC=BD=94=EB=93=9C=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/middleware.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/middleware.ts b/src/middleware.ts index d940905..5a49700 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -9,7 +9,7 @@ export function middleware(request: NextRequest) { const url = request.nextUrl; const hostname = request.headers .get("host")! - .replace(".localhost:3000", `.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}`); + .replace(".localhost:3000", `.${process.env.ROOT_DOMAIN}`); const searchParams = request.nextUrl.searchParams.toString(); const path = `${url.pathname}${ @@ -17,10 +17,8 @@ export function middleware(request: NextRequest) { }`; const subDomain = hostname.split(".")[0]; - switch (true) { case subDomain !== hostname: - console.log(`/pg/${subDomain}${path}`); return NextResponse.rewrite( new URL(`/pg/${subDomain}${path}`, request.url), ); From dd25c3bdfbb51b546b1dc02f2f84970d413938b0 Mon Sep 17 00:00:00 2001 From: WooWan Date: Tue, 6 Aug 2024 19:44:29 +0900 Subject: [PATCH 5/5] =?UTF-8?q?chore:=20ROOT=5FDOMAIN=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.template | 2 -- src/middleware.ts | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.env.template b/.env.template index b245079..e4b203f 100644 --- a/.env.template +++ b/.env.template @@ -27,5 +27,3 @@ NAVER_REDIRECT_URI= KAKAO_MAP_BASE_URL= KAKAO_MAP_API_KEY= DAUMCDN_POSTOCDE_URL= - -ROOT_DOMAIN= \ No newline at end of file diff --git a/src/middleware.ts b/src/middleware.ts index 5a49700..aff80a5 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -7,9 +7,7 @@ export const config = { export function middleware(request: NextRequest) { const url = request.nextUrl; - const hostname = request.headers - .get("host")! - .replace(".localhost:3000", `.${process.env.ROOT_DOMAIN}`); + const hostname = request.headers.get("host")!; const searchParams = request.nextUrl.searchParams.toString(); const path = `${url.pathname}${ @@ -17,6 +15,8 @@ export function middleware(request: NextRequest) { }`; const subDomain = hostname.split(".")[0]; + console.log("subDomain", subDomain, "hostname", hostname); + switch (true) { case subDomain !== hostname: return NextResponse.rewrite(