update user host

This commit is contained in:
Junlai
2023-04-04 03:34:33 +00:00
parent 7d7f3716be
commit 22ec525618
9 changed files with 52 additions and 4 deletions

View File

@@ -3,12 +3,13 @@ import { NextRequest } from "next/server";
const OPENAI_URL = "api.openai.com";
const DEFAULT_PROTOCOL = "https";
const PROTOCOL = process.env.PROTOCOL ?? DEFAULT_PROTOCOL;
const BASE_URL = process.env.BASE_URL ?? OPENAI_URL;
export async function requestOpenai(req: NextRequest) {
const apiKey = req.headers.get("token");
const openaiPath = req.headers.get("path");
const userHost = req.headers.get("userhost");
const BASE_URL = userHost ?? process.env.BASE_URL ?? OPENAI_URL;
console.log("[BASE_URL] ", openaiPath);
console.log("[Proxy] ", openaiPath);
return fetch(`${PROTOCOL}://${BASE_URL}/${openaiPath}`, {