From 807f6f0194cb77c02132efb593a704504473ce6f Mon Sep 17 00:00:00 2001 From: Vojtech Vondra Date: Sun, 5 Aug 2018 18:37:44 +0200 Subject: [PATCH] Key endpoint gets both JSON and urlencoded data --- src/keys.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/keys.js b/src/keys.js index c8394e9..7065a7f 100644 --- a/src/keys.js +++ b/src/keys.js @@ -9,7 +9,13 @@ export const handler = async (event, context, callback) => { return; } - const body = utils.normalizeBody(querystring.parse(event.body)); + let body; + const contentType = event.headers['Content-Type'].split(';')[0]; + if (contentType === 'application/json') { + body = utils.normalizeBody(JSON.parse(event.body)); + } else { + body = utils.normalizeBody(querystring.parse(event.body)); + } let user; let device;