mirror of
https://github.com/labring/FastGPT.git
synced 2026-02-27 01:02:22 +08:00
fix: plugin redirect (#6232)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user