fix(web): conversation DELETE — resolve Failed to fetch TypeError
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
ci/woodpecker/push/ci Pipeline was successful

Root cause: @fastify/cors default allowed methods are only GET, HEAD, POST
(CORS-safelisted methods). DELETE requires a CORS preflight OPTIONS request,
and without DELETE in Access-Control-Allow-Methods the browser rejects it
with TypeError: Failed to fetch before the request reaches the server.

Fix: explicitly set methods in enableCors() to include DELETE and all other
HTTP verbs used by the API.

Also add try/catch to handleDelete in ChatPage so errors surface in the
console rather than becoming unhandled promise rejections.

Fixes #195.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-16 21:38:48 -05:00
parent 1f2b8125c6
commit 9f046693be
2 changed files with 10 additions and 5 deletions

View File

@@ -40,6 +40,7 @@ async function bootstrap(): Promise<void> {
app.enableCors({ app.enableCors({
origin: process.env['GATEWAY_CORS_ORIGIN'] ?? 'http://localhost:3000', origin: process.env['GATEWAY_CORS_ORIGIN'] ?? 'http://localhost:3000',
credentials: true, credentials: true,
methods: ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
}); });
await app.register(helmet as never, { contentSecurityPolicy: false }); await app.register(helmet as never, { contentSecurityPolicy: false });

View File

@@ -151,11 +151,15 @@ export default function ChatPage(): React.ReactElement {
const handleDelete = useCallback( const handleDelete = useCallback(
async (id: string) => { async (id: string) => {
await api<void>(`/api/conversations/${id}`, { method: 'DELETE' }); try {
setConversations((prev) => prev.filter((c) => c.id !== id)); await api<void>(`/api/conversations/${id}`, { method: 'DELETE' });
if (activeId === id) { setConversations((prev) => prev.filter((c) => c.id !== id));
setActiveId(null); if (activeId === id) {
setMessages([]); setActiveId(null);
setMessages([]);
}
} catch (err) {
console.error('[ChatPage] Failed to delete conversation:', err);
} }
}, },
[activeId], [activeId],