mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-10-31 14:23:43 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			33 lines
		
	
	
		
			823 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			823 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { ModelProvider } from "@/app/constant";
 | |
| import { prettyObject } from "@/app/utils/format";
 | |
| import { NextRequest, NextResponse } from "next/server";
 | |
| import { auth } from "./auth";
 | |
| import { requestOpenai } from "./common";
 | |
| 
 | |
| export async function handle(
 | |
|   req: NextRequest,
 | |
|   { params }: { params: { path: string[] } },
 | |
| ) {
 | |
|   console.log("[Azure Route] params ", params);
 | |
| 
 | |
|   if (req.method === "OPTIONS") {
 | |
|     return NextResponse.json({ body: "OK" }, { status: 200 });
 | |
|   }
 | |
| 
 | |
|   const subpath = params.path.join("/");
 | |
| 
 | |
|   const authResult = auth(req, ModelProvider.GPT);
 | |
|   if (authResult.error) {
 | |
|     return NextResponse.json(authResult, {
 | |
|       status: 401,
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   try {
 | |
|     return await requestOpenai(req);
 | |
|   } catch (e) {
 | |
|     console.error("[Azure] ", e);
 | |
|     return NextResponse.json(prettyObject(e));
 | |
|   }
 | |
| }
 |