From 8939bcd25874df196f42d9ef1a15e0d59764dfd7 Mon Sep 17 00:00:00 2001 From: weaigc <879821485@qq.com> Date: Sat, 19 Aug 2023 17:54:51 +0800 Subject: [PATCH] tmp: add test proxy --- src/components/chat-panel.tsx | 2 +- src/components/chat-suggestions.tsx | 2 +- src/components/voice.tsx | 2 +- src/pages/api/proxy.ts | 12 ++++++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/components/chat-panel.tsx b/src/components/chat-panel.tsx index 1fbc3c2b..56b2112b 100644 --- a/src/components/chat-panel.tsx +++ b/src/components/chat-panel.tsx @@ -75,7 +75,7 @@ export function ChatPanel({ if (input) { setFocus() } - }, [input]) + }, [input, setFocus]) return (
{ setSuggestions(suggestions) window.scrollBy(0, 2000) - }, [suggestions.length]) + }, [suggestions.length, setSuggestions]) return currentSuggestions?.length ? (
diff --git a/src/components/voice.tsx b/src/components/voice.tsx index 074d0e14..ab886394 100644 --- a/src/components/voice.tsx +++ b/src/components/voice.tsx @@ -31,7 +31,7 @@ const Voice = ({ setInput, input, sendMessage, isSpeaking }: Pick { setListen(enable) diff --git a/src/pages/api/proxy.ts b/src/pages/api/proxy.ts index 4480a6d4..240b5fb5 100644 --- a/src/pages/api/proxy.ts +++ b/src/pages/api/proxy.ts @@ -9,10 +9,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) if (!url) { return res.end('ok') } - const response = await fetch(url, { headers, method, body }) - .then((res) => res.text()) - - res.end(response) + const response = await fetch(url, { headers, method, body, redirect: 'manual' }) + const text = await response.text() + res.writeHead(200, { + 'Content-Type': 'application/text', + 'x-url': response.url, + 'x-status': response.status, + }) + res.end(text) } catch (e) { console.log(e) return res.end(e)