mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-30 02:12:38 +00:00

* feishu app release (#85) * Revert "lafAccount add pat & re request when token invalid (#76)" (#77) This reverts commit 83d85dfe37adcaef4833385ea52ee79fd84720be. * perf: workflow ux * system config * feat: feishu app release * chore: sovle the conflicts files; fix the feishu entry * fix: rename Feishu interface to FeishuType * fix: fix type problem in app.ts * fix: type problem * fix: style problem --------- Co-authored-by: Archer <545436317@qq.com> * perf: publish channel code * change system variable position (#94) * perf: workflow context * perf: variable select * hide publish * perf: simple edit auto refresh * perf: simple edit data refresh * fix: target handle --------- Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com> Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
import { jsonRes } from '@fastgpt/service/common/response';
|
|
import { connectToDatabase } from '@/service/mongo';
|
|
import { request } from 'https';
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
try {
|
|
await connectToDatabase();
|
|
const { path = [], ...query } = req.query as any;
|
|
|
|
const queryStr = new URLSearchParams(query).toString();
|
|
const requestPath = queryStr
|
|
? `/${path?.join('/')}?${new URLSearchParams(query).toString()}`
|
|
: `/${path?.join('/')}`;
|
|
|
|
if (!requestPath) {
|
|
throw new Error('url is empty');
|
|
}
|
|
|
|
const lafEnv = global.feConfigs?.lafEnv;
|
|
|
|
if (!lafEnv) {
|
|
throw new Error('lafEnv is empty');
|
|
}
|
|
|
|
const parsedUrl = new URL(lafEnv);
|
|
delete req.headers?.cookie;
|
|
delete req.headers?.host;
|
|
delete req.headers?.origin;
|
|
|
|
const requestResult = request({
|
|
protocol: parsedUrl.protocol,
|
|
hostname: parsedUrl.hostname,
|
|
port: parsedUrl.port,
|
|
path: requestPath,
|
|
method: req.method,
|
|
headers: req.headers,
|
|
timeout: 30000
|
|
});
|
|
|
|
req.pipe(requestResult);
|
|
|
|
requestResult.on('response', (response) => {
|
|
Object.keys(response.headers).forEach((key) => {
|
|
// @ts-ignore
|
|
res.setHeader(key, response.headers[key]);
|
|
});
|
|
response.statusCode && res.writeHead(response.statusCode);
|
|
response.pipe(res);
|
|
});
|
|
requestResult.on('error', (e) => {
|
|
res.send(e);
|
|
res.end();
|
|
});
|
|
} catch (error) {
|
|
jsonRes(res, {
|
|
code: 500,
|
|
error
|
|
});
|
|
}
|
|
}
|
|
|
|
export const config = {
|
|
api: {
|
|
bodyParser: false
|
|
}
|
|
};
|