GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — ChatGPT-Next-Web/middleware.ts at main · gitlanyi/ChatGPT-Next-Web Expand file tree/ Copy pathmiddleware.tsMore file actions 59 lines (52 loc) · 1.42 KB / Copy pathmiddleware.tsFile metadata and controls59 lines (52 loc) · 1.42 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 import { NextRequest, NextResponse } from "next/server"; import { getServerSideConfig } from "./app/config/server"; import md5 from "spark-md5"; export const config = { matcher: ["/api/openai", "/api/chat-stream"], }; const serverConfig = getServerSideConfig(); export function middleware(req: NextRequest) { const accessCode = req.headers.get("access-code"); const token = req.headers.get("token"); const hashedCode = md5.hash(accessCode ?? "").trim(); console.log("[Auth] allowed hashed codes: ", [...serverConfig.codes]); console.log("[Auth] got access code:", accessCode); console.log("[Auth] hashed access code:", hashedCode); if (serverConfig.needCode && !serverConfig.codes.has(hashedCode) && !token) { return NextResponse.json( { error: true, needAccessCode: true, msg: "Please go settings page and fill your access code.", }, { status: 401, }, ); } // inject api key if (!token) { const apiKey = serverConfig.apiKey; if (apiKey) { console.log("[Auth] set system token"); req.headers.set("token", apiKey); } else { return NextResponse.json( { error: true, msg: "Empty Api Key", }, { status: 401, }, ); } } else { console.log("[Auth] set user token"); } return NextResponse.next({ request: { headers: req.headers, }, }); } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |