mirror of
				https://github.com/Yidadaa/ChatGPT-Next-Web.git
				synced 2025-11-04 00:16:11 +08:00 
			
		
		
		
	add missing file
This commit is contained in:
		
							
								
								
									
										57
									
								
								app/api/azure/[...path]/route.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								app/api/azure/[...path]/route.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,57 @@
 | 
				
			|||||||
 | 
					import { getServerSideConfig } from "@/app/config/server";
 | 
				
			||||||
 | 
					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";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const GET = handle;
 | 
				
			||||||
 | 
					export const POST = handle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const runtime = "edge";
 | 
				
			||||||
 | 
					export const preferredRegion = [
 | 
				
			||||||
 | 
					  "arn1",
 | 
				
			||||||
 | 
					  "bom1",
 | 
				
			||||||
 | 
					  "cdg1",
 | 
				
			||||||
 | 
					  "cle1",
 | 
				
			||||||
 | 
					  "cpt1",
 | 
				
			||||||
 | 
					  "dub1",
 | 
				
			||||||
 | 
					  "fra1",
 | 
				
			||||||
 | 
					  "gru1",
 | 
				
			||||||
 | 
					  "hnd1",
 | 
				
			||||||
 | 
					  "iad1",
 | 
				
			||||||
 | 
					  "icn1",
 | 
				
			||||||
 | 
					  "kix1",
 | 
				
			||||||
 | 
					  "lhr1",
 | 
				
			||||||
 | 
					  "pdx1",
 | 
				
			||||||
 | 
					  "sfo1",
 | 
				
			||||||
 | 
					  "sin1",
 | 
				
			||||||
 | 
					  "syd1",
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
		Reference in New Issue
	
	Block a user