From ee1c7820c3705a1e1a27307c0dfe1e6577ed5d9e Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 12 Jun 2026 23:33:47 -0400 Subject: [PATCH] x --- apps/backend/src/routes/line.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/backend/src/routes/line.ts b/apps/backend/src/routes/line.ts index cbd63bb..af2781b 100644 --- a/apps/backend/src/routes/line.ts +++ b/apps/backend/src/routes/line.ts @@ -4,6 +4,11 @@ import { lineConfig, lineClient } from '../lib/lineClient'; import crypto from 'crypto'; export const lineRoutes = new Elysia({ prefix: '/line' }) + .onParse(async ({ request, contentType }) => { + if (contentType?.includes('application/json')) { + return await request.text(); + } + }) .post('/webhook', async ({ request, body, set }) => { // 1. Verify Signature const signature = request.headers.get('x-line-signature'); @@ -12,9 +17,7 @@ export const lineRoutes = new Elysia({ prefix: '/line' }) return { error: 'Missing Signature' }; } - // In Elysia, application/json is automatically parsed into an object. - // We stringify it back to a string for signature validation. - // Note: This works if the original payload didn't have special formatting spaces. + // In our onParse hook, we intercepted the body and returned it as a raw text string. const rawBody = typeof body === 'string' ? body : JSON.stringify(body); if (!rawBody) { @@ -62,6 +65,4 @@ export const lineRoutes = new Elysia({ prefix: '/line' }) set.status = 500; return { error: 'Webhook processing failed' }; } - }, { - type: 'text' });