Skip to content

Commit

Permalink
[Web] [Chore] 미들웨어로 모바일 접속 시 리다이렉트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
suwonthugger committed Nov 10, 2024
1 parent 7387ba2 commit 5231f63
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions apps/web/middleware.ts
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*', // 모든 경로에 적용
};

0 comments on commit 5231f63

Please sign in to comment.