mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-09 19:46:37 +08:00
添加middleware
This commit is contained in:
parent
b2c711a5e8
commit
8239551e8e
@ -3,7 +3,7 @@ import { getServerSideConfig } from "./app/config/server";
|
||||
import md5 from "spark-md5";
|
||||
|
||||
export const config = {
|
||||
matcher: ["/api/openai", "/api/chat-stream"],
|
||||
matcher: ['/', '/index',"/api/openai", "/api/chat-stream"],
|
||||
};
|
||||
|
||||
const serverConfig = getServerSideConfig();
|
||||
@ -23,7 +23,20 @@ export function middleware(req: NextRequest) {
|
||||
const accessCode = req.headers.get("access-code");
|
||||
const token = req.headers.get("token");
|
||||
const hashedCode = md5.hash(accessCode ?? "").trim();
|
||||
const basicAuth = req.headers.get('authorization')
|
||||
const url = req.nextUrl
|
||||
|
||||
if (basicAuth) {
|
||||
const authValue = basicAuth.split(' ')[1]
|
||||
const [user, pwd] = atob(authValue).split(':')
|
||||
|
||||
if (user === '4dmin' && pwd === 'testpwd123') {
|
||||
return NextResponse.next()
|
||||
}
|
||||
}else{
|
||||
url.pathname = '/api/auth'
|
||||
return NextResponse.rewrite(url)
|
||||
}
|
||||
console.log("[Auth] allowed hashed codes: ", [...serverConfig.codes]);
|
||||
console.log("[Auth] got access code:", accessCode);
|
||||
console.log("[Auth] hashed access code:", hashedCode);
|
||||
|
Loading…
Reference in New Issue
Block a user