From 1b030eef1cf6cc052a70c48dfae94ac12ef60dba Mon Sep 17 00:00:00 2001 From: Sven Sauleau Date: Tue, 17 Jan 2023 08:33:28 +0000 Subject: [PATCH] MOW-106: /api/v1/apps support JSON and FormData --- backend/test/mastodon.spec.ts | 3 +++ functions/api/v1/apps.ts | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/test/mastodon.spec.ts b/backend/test/mastodon.spec.ts index 9adfbd5..8bb2760 100644 --- a/backend/test/mastodon.spec.ts +++ b/backend/test/mastodon.spec.ts @@ -93,6 +93,9 @@ describe('Mastodon APIs', () => { const request = new Request('https://example.com', { method: 'POST', body: '{"redirect_uris":"mastodon://joinmastodon.org/oauth","website":"https://app.joinmastodon.org/ios","client_name":"Mastodon for iOS","scopes":"read write follow push"}', + headers: { + 'content-type': 'application/json', + }, }) const res = await apps.handleRequest(db, request, vapidKeys) diff --git a/functions/api/v1/apps.ts b/functions/api/v1/apps.ts index 40821d6..17906fb 100644 --- a/functions/api/v1/apps.ts +++ b/functions/api/v1/apps.ts @@ -4,6 +4,7 @@ import { Env } from 'wildebeest/backend/src/types/env' import { createClient } from 'wildebeest/backend/src/mastodon/client' import { VAPIDPublicKey } from 'wildebeest/backend/src/mastodon/subscription' import { getVAPIDKeys } from 'wildebeest/backend/src/config' +import { readBody } from 'wildebeest/backend/src/utils/body' type AppsPost = { redirect_uris: string @@ -21,7 +22,7 @@ export async function handleRequest(db: D1Database, request: Request, vapidKeys: return new Response('', { status: 400 }) } - const body = await request.json() + const body = await readBody(request) const client = await createClient(db, body.client_name, body.redirect_uris, body.website, body.scopes) const vapidKey = VAPIDPublicKey(vapidKeys)