From 377d12b820d65632de84858655120904652308b0 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Thu, 13 Nov 2025 00:05:30 +0100 Subject: [PATCH] Add /leave endpoint to end sessions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add POST /leave endpoint that deletes offers by code - Allows either peer to end the session - Returns success confirmation This enables proper session cleanup when either peer wants to explicitly end the connection. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/app.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/app.ts b/src/app.ts index fd8dfad..e9aad56 100644 --- a/src/app.ts +++ b/src/app.ts @@ -190,5 +190,28 @@ export function createApp(storage: Storage, config: AppConfig) { } }); + /** + * POST /leave + * Ends a session by deleting the offer + * Body: { code: string } + */ + app.post('/leave', async (c) => { + try { + const body = await c.req.json(); + const { code } = body; + + if (!code || typeof code !== 'string') { + return c.json({ error: 'Missing or invalid required parameter: code' }, 400); + } + + await storage.deleteOffer(code); + + return c.json({ success: true }, 200); + } catch (err) { + console.error('Error leaving session:', err); + return c.json({ error: 'Internal server error' }, 500); + } + }); + return app; }