Skip to content

Commit 9ff1c84

Browse files
Allow POST requests to query (so that we can have large error messages)
1 parent 0713cc0 commit 9ff1c84

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

api/abstractplay.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,35 @@ function setsEqual(a: Set<any>, b: Set<any>): boolean {
515515
return true;
516516
}
517517

518-
module.exports.query = async (event: { queryStringParameters: any; }) => {
518+
module.exports.query = async (event: { queryStringParameters: any; body?: string; httpMethod: string; }) => {
519519
console.log(event);
520-
const pars = event.queryStringParameters;
520+
521+
let pars;
522+
let query;
523+
524+
// Handle both GET (query parameters) and POST (JSON body) requests
525+
if (event.httpMethod === 'POST' && event.body) {
526+
try {
527+
const bodyData = JSON.parse(event.body);
528+
query = bodyData.query;
529+
pars = bodyData.pars || {};
530+
} catch (error) {
531+
return {
532+
statusCode: 400,
533+
body: JSON.stringify({
534+
message: "Invalid JSON in request body"
535+
}),
536+
headers
537+
};
538+
}
539+
} else {
540+
// Existing GET request handling
541+
pars = event.queryStringParameters;
542+
query = pars.query;
543+
}
544+
521545
console.log(pars);
522-
switch (pars.query) {
546+
switch (query) {
523547
case "user_names":
524548
return await userNames();
525549
case "challenge_details":

serverless.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,17 @@ functions:
157157
- 'cognito:username'
158158
query:
159159
handler: api/abstractplay.query
160-
memorySize: 128
160+
memorySize: 256
161161
description: Abstract Play queries that does not need authorization.
162162
events:
163163
- http:
164164
path: query
165165
method: get
166166
cors: true
167+
- http:
168+
path: query
169+
method: post
170+
cors: true
167171
yourturn:
168172
handler: utils/yourturn.handler
169173
description: Sends out "your turn" notifications

0 commit comments

Comments
 (0)