Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Pass rawBody instead of parsed #62

Open
cvanputt opened this issue Mar 5, 2021 · 0 comments
Open

Pass rawBody instead of parsed #62

cvanputt opened this issue Mar 5, 2021 · 0 comments

Comments

@cvanputt
Copy link

cvanputt commented Mar 5, 2021

I customized this module locally and added a jsonParse flag to the routes so that I can have the option to parse or not parse a JSON event body. Since I don't know typescript I can't do a pull request on your code but this is a very quick to add and useful feature.

example route:

routes: [
      {
        path: '/somepath',
        method: 'POST',
        action: async (event) => {
         //some function
          };
          return response;
        },
       jsonParse: true
      }
]

code change (javascript proxyIntegration.js line 80):

    if (event.body && actionConfig.jsonParse) {
      try {
        proxyEvent.body = JSON.parse(event.body);
      } catch (parseError) {
        console.log(`Could not parse body as json: ${event.body}`, parseError);
        return {
          statusCode: 400,
          headers,
          body: JSON.stringify({ message: 'body is not a valid JSON', error: 'ParseError' }),
        };
      }
    } else proxyEvent.body = event.body;
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant