From 2d2d7bb8222268eac4ab5c3ac8f4a3b84882564e Mon Sep 17 00:00:00 2001 From: Izan Gil <66965250+SrIzan10@users.noreply.github.com> Date: Sun, 21 Apr 2024 20:45:04 +0200 Subject: [PATCH] feat: data query parameter --- src/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 446d5e6..12a4d11 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,12 +15,15 @@ function randomString(length = 5) { } app.get('/', async (c) => { - return c.text('this is featherbin, create a paste by POSTing to /paste with the content in the body\nhttps://github.com/SrIzan10/featherbin') + return c.text('this is featherbin, create a paste by POSTing to /paste with the content in the body or as a query parameter called "data"\nhttps://github.com/SrIzan10/featherbin') }) app.post('/paste', async (c) => { const id = randomString() - const content = await c.req.text() + const content = await c.req.text() || c.req.query('data') + if (!content) { + return c.text('no content provided', 400) + } await c.env.featherbin.put(id, content) return c.json({ id }) })