Skip to content

Commit

Permalink
[Common] [Chore] 미들 웨어 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
suwonthugger committed Nov 10, 2024
1 parent 64a6bad commit 4ab0898
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions apps/web/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// middleware.js
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;

// 모바일 서브도메인으로 이미 접속한 경우 무시
if (host.startsWith('m.')) {
return NextResponse.next();
}
console.log(`Middleware invoked for host: ${host}, path: ${pathname}`);

// 모바일 기기 감지
const userAgent = req.headers.get('user-agent') || '';
Expand All @@ -18,6 +14,8 @@ export function middleware(req: NextRequest) {
userAgent,
);

console.log(isMobile);

if (isMobile) {
// 모바일 서브도메인으로 리다이렉션
url.hostname = `m.${url.hostname}`;
Expand Down

0 comments on commit 4ab0898

Please sign in to comment.