添加middleware

This commit is contained in:
gordongpan 2023-04-20 20:31:24 +08:00
parent 8239551e8e
commit 202fddd6e8

View File

@ -31,12 +31,7 @@ export function middleware(req: NextRequest) {
const [user, pwd] = atob(authValue).split(':') const [user, pwd] = atob(authValue).split(':')
if (user === '4dmin' && pwd === 'testpwd123') { if (user === '4dmin' && pwd === 'testpwd123') {
return NextResponse.next() // return NextResponse.next()
}
}else{
url.pathname = '/api/auth'
return NextResponse.rewrite(url)
}
console.log("[Auth] allowed hashed codes: ", [...serverConfig.codes]); console.log("[Auth] allowed hashed codes: ", [...serverConfig.codes]);
console.log("[Auth] got access code:", accessCode); console.log("[Auth] got access code:", accessCode);
console.log("[Auth] hashed access code:", hashedCode); console.log("[Auth] hashed access code:", hashedCode);
@ -82,4 +77,9 @@ export function middleware(req: NextRequest) {
headers: req.headers, headers: req.headers,
}, },
}); });
}
}else{
url.pathname = '/api/auth'
return NextResponse.rewrite(url)
}
} }