From 030bf007cc5a890dc7789f9f7878db84cdf0196e Mon Sep 17 00:00:00 2001 From: christiankrag Date: Mon, 15 Dec 2025 06:06:27 +0100 Subject: [PATCH] Use text() for both request and response parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - request.json() may not be available in wws - Parse request body manually with JSON.parse 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- chat/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/chat/index.js b/chat/index.js index f05aab0..1922c9d 100644 --- a/chat/index.js +++ b/chat/index.js @@ -18,7 +18,18 @@ const handler = async (request) => { } try { - const body = await request.json() + // Use text() and parse manually - json() may not be available in wws + const bodyText = await request.text() + let body + try { + body = JSON.parse(bodyText) + } catch (e) { + let response = new Response(JSON.stringify({ error: 'Invalid JSON body' })) + response.headers.set('Content-Type', 'application/json') + response.headers.set('Access-Control-Allow-Origin', '*') + return response + } + const message = body.message const project_id = body.project_id const user_id = body.user_id @@ -45,7 +56,7 @@ const handler = async (request) => { }) }) - // Use text() and parse manually (json() may not be available in wws) + // Use text() and parse manually const responseText = await n8nResponse.text() let result try {