Skip to content

Add CORS support (Serverless v1) #1586

@patoncrispy

Description

@patoncrispy
Feature Request:

I'd like to enable CORS support for API Gateway endpoints in Serverless v1. A schema example could look like this:

functions: 
  user:
    handler: handler.user
    events:
      - http:
          method: post
          cors: true
custom: 
    cors:
        allow-origin: '*'
        allow-headers:
            - Content-Type
            - X-Amz-Date
            - Authorization
            - X-Api-Key
        allow-methods:
            - POST
plugins:
    - api-gateway-cors-plugin

When run (with deployment), it will create the OPTIONS method and the appropriate 200 responses for specified methods, adding the specified origin and headers. Headers, Methods and Origin are required headers by API Gateway, so I reckon a warning should be printed letting the user know what they need to specify. It could also display other validation warnings, such as having wildcard (*) header/origin settings, or if a setting isn't supported by API Gateway, etc., though it would probably be good to have an option to suppress warnings for specific stages.

Benefits:
  • It will enable easier development of single page apps.
  • We can have CORS support for API Gateway. Yay!
Drawbacks:
  • None that I can think of...

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions