You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a21af36
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -403,6 +403,7 @@ functions:
403
403
- http:
404
404
path: create
405
405
method: post
406
+
cors: true
406
407
summary:
407
408
documentation:
408
409
summary: "Create User"
@@ -645,6 +646,12 @@ responseHeaders:
645
646
type: integer
646
647
```
647
648
649
+
###### CORS
650
+
651
+
You can automatically generate CORS response headers by setting `cors` at the function level. Serverless allows you to modify how CORS is setup, so you can have the default options with `cors: true`, or you can modify the settings as shown in the [serverless documentation for CORS](https://www.serverless.com/framework/docs/providers/aws/events/apigateway#enabling-cors).
652
+
653
+
The generator will interpret your settings for CORS and automatically add the response headers. If for whatever reason you wish to override these, you can set them via the above `responseHeaders` setting and it'll apply your overrides.
654
+
648
655
## Example configuration
649
656
650
657
Please view the example [serverless.yml](test/serverless-tests/serverless%202/serverless.yml).
Copy file name to clipboardExpand all lines: src/definitionGenerator.js
+73Lines changed: 73 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,24 @@ class DefinitionGenerator {
35
35
securitySchemes: 'securitySchemes'
36
36
}
37
37
38
+
this.DEFAULT_CORS_HEADERS={
39
+
'Access-Control-Allow-Origin': {
40
+
description: 'The Access-Control-Allow-Origin response header indicates whether the response can be shared with requesting code from the given origin.',
41
+
schema: {
42
+
type: 'string',
43
+
default: '*',
44
+
example: 'https://developer.mozilla.org'
45
+
}
46
+
},
47
+
'Access-Control-Allow-Credentials': {
48
+
description: `The Access-Control-Allow-Credentials response header tells browsers whether to expose the response to the frontend JavaScript code when the request's credentials mode (Request.credentials) is include`,
0 commit comments