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

Pass rawBody instead of parsed #62

@cvanputt

Description

@cvanputt

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions