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

CORS not getting enabled on POST via API Gateway #33

@shikhar1987

Description

@shikhar1987

Enabling cors via API gateway doesn't return the required headers. Looks like you cannot enable CORS via API gateway if you've configured lambda as proxy integration. This is mentioned here:
https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html#how-to-cors-consolelf.

Had to manually update the lambda code to include the following:

                "Access-Control-Allow-Headers" : "Content-Type",
                "Access-Control-Allow-Methods": "OPTIONS,POST,GET"

Here's the place where you should modify in case you run into a similar issue:

        callback(null, {
            statusCode: 201,
            body: JSON.stringify({
                RideId: rideId,
                Unicorn: unicorn,
                UnicornName: unicorn.Name,
                Eta: '30 seconds',
                Rider: username,
            }),
            headers: {
                'Access-Control-Allow-Origin': '*',
                "Access-Control-Allow-Headers" : "Content-Type",
                "Access-Control-Allow-Methods": "OPTIONS,POST,GET"
            },
        });

This now makes the unicorn pop up in my requested location.

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