fix: plugin redirect (#6232)

This commit is contained in:
Archer
2026-01-11 00:26:41 +08:00
committed by GitHub
parent e8eba6300d
commit 0beb52a2f3
2 changed files with 2 additions and 34 deletions

View File

@@ -1,9 +1,11 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@fastgpt/service/common/response';
import { Readable } from 'stream';
import { authSystemAdmin } from '@fastgpt/service/support/permission/user/auth';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
await authSystemAdmin({ req });
const { path = [], ...query } = req.query as any;
const queryStr = new URLSearchParams(query).toString();

View File

@@ -1,34 +0,0 @@
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
import { PLUGIN_BASE_URL, PLUGIN_TOKEN } from '@fastgpt/service/thirdProvider/fastgptPlugin';
export type PluginQuery = {
pluginRequestPath: string[];
};
export type PluginBody = {};
export type PluginResponse = {};
async function handler(req: ApiRequestProps<PluginBody, PluginQuery>, res: ApiResponseType<any>) {
const { pluginRequestPath } = req.query;
const urlObj = new URL(pluginRequestPath.join('/'), PLUGIN_BASE_URL);
Object.entries(req.query).forEach(([key, value]) => {
if (key !== 'pluginRequestPath') {
urlObj.searchParams.set(key, String(value));
}
});
const body =
req.method?.toUpperCase() === 'POST' || req.method === 'PUT'
? JSON.stringify(req.body)
: undefined;
const pluginRes = await fetch(urlObj.toString(), {
method: req.method,
body,
headers: {
authtoken: PLUGIN_TOKEN,
'Content-Type': 'application/json'
}
});
res.status(pluginRes.status);
res.json(await pluginRes.json());
}
export default handler;