(req: NextRequest)
| 5 | } |
| 6 | |
| 7 | export default function middleware(req: NextRequest) { |
| 8 | const basicAuth = req.headers.get('authorization') |
| 9 | const url = req.nextUrl |
| 10 | |
| 11 | if (basicAuth) { |
| 12 | const authValue = basicAuth.split(' ')[1] |
| 13 | const [user, pwd] = atob(authValue).split(':') |
| 14 | |
| 15 | if (user === '4dmin' && pwd === 'testpwd123') { |
| 16 | return NextResponse.next() |
| 17 | } |
| 18 | } |
| 19 | url.pathname = '/api/auth' |
| 20 | |
| 21 | return NextResponse.rewrite(url) |
| 22 | } |