-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Web] [Chore] 미들웨어로 모바일 접속 시 리다이렉트 추가
- Loading branch information
1 parent
7387ba2
commit 5231f63
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// apps/web/middleware.ts | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
export function middleware(req: NextRequest) { | ||
const url = req.nextUrl.clone(); | ||
const host = req.headers.get('host') || ''; | ||
const pathname = req.nextUrl.pathname; | ||
|
||
// 모바일 기기 감지 | ||
const userAgent = req.headers.get('user-agent') || ''; | ||
const isMobile = | ||
/Mobi|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( | ||
userAgent, | ||
); | ||
|
||
if (host === 'm.rankit.run') { | ||
return NextResponse.next(); | ||
} | ||
|
||
if (isMobile) { | ||
url.hostname = 'm.rankit.run'; | ||
return NextResponse.redirect(url); | ||
} | ||
|
||
return NextResponse.next(); | ||
} | ||
|
||
export const config = { | ||
matcher: '/:path*', // 모든 경로에 적용 | ||
}; |