fix: Add cache fix for request Usage

Added cache: 'no-store' parameter to fetch to avoid caching issue in non-Vercel deployment environment(ref: https://beta.nextjs.org/docs/data-fetching/fetching#dynamic-data-fetching)
This commit is contained in:
ガオガオ
2023-04-13 01:27:11 +08:00
parent 8da581695f
commit d2ee1bd212
4 changed files with 20 additions and 8 deletions

View File

@@ -8,6 +8,8 @@ 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 fetchCache =
req.headers.get("fetch-cache") == "enable" ? "default" : "no-store";
let baseUrl = BASE_URL;
@@ -23,6 +25,7 @@ export async function requestOpenai(req: NextRequest) {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
},
cache: fetchCache,
method: req.method,
body: req.body,
});