serverless lambda cors code example
Example 1: cors header missing vue api gateway
1# serverless.yml
2
3service: products-service
4
5provider:
6 name: aws
7 runtime: nodejs6.10
8
9functions:
10 getProduct:
11 handler: handler.getProduct
12 events:
13 - http:
14 path: product/{id}
15 method: get
16 cors: true # <-- CORS!
17 createProduct:
18 handler: handler.createProduct
19 events:
20 - http:
21 path: product
22 method: post
23 cors: true # <-- CORS!
Example 2: cors header missing vue api gateway
1# serverless.yml
2
3...
4
5 resources:
6 Resources:
7 GatewayResponseDefault4XX:
8 Type: 'AWS::ApiGateway::GatewayResponse'
9 Properties:
10 ResponseParameters:
11 gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
12 gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
13 ResponseType: DEFAULT_4XX
14 RestApiId:
15 Ref: 'ApiGatewayRestApi'
16 ```