Skip to content

Commit bf2437d

Browse files
committed
re-add cors() middleware by default
1 parent 923a6de commit bf2437d

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,7 @@ If you prefer not to use the serverless.js framework, you can also deploy your
7171

7272
Note 1: Change your process.env.AWS_STAGE_NAME to "/default" to match the default stage name for manually deployed API Gateways.
7373

74-
Note 2: To enable cors with a manual deployment, you should add cors middleware to the top of combineMiddleware() in index.js.
75-
76-
```
77-
const cors = require('cors');
78-
const app = combineMiddlewares([
79-
// CORS middleware to permit cross-site API requests. Configure to taste
80-
cors(),
81-
82-
(req, res, next) => { ... },
83-
postgraphile(...)
84-
...
85-
```
74+
Note 2: CORS is enabled by default. Remove cors() middleware in `/src/index.js` if you would prefer disabled cors.
8675

8776
0. Run `yarn build` to create `lambda.zip` file that you can upload to Amazon Lambda.
8877
1. Visit https://console.aws.amazon.com/lambda/home and click 'Create function'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"dependencies": {
1414
"aws-serverless-express": "^3.3.5",
15+
"cors": "^2.8.5",
1516
"pg": "7.4.1",
1617
"postgraphile": "v4.2",
1718
"postgraphile-core": "^4.2.0"

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const awsServerlessExpress = require('aws-serverless-express');
22
const { postgraphile } = require('postgraphile');
33
const { options } = require('./postgraphileOptions');
44
const combineMiddlewares = require('./combineMiddlewares');
5+
const cors = require('cors');
56

67
const schemas = process.env.DATABASE_SCHEMAS
78
? process.env.DATABASE_SCHEMAS.split(',')
@@ -13,6 +14,9 @@ const app = combineMiddlewares([
1314
*
1415
* This is typically useful for augmenting the request before it goes to PostGraphile.
1516
*/
17+
18+
// CORS middleware to permit cross-site API requests. Configure to taste
19+
cors(),
1620

1721
// Determines the effective URL we are at if `absoluteRoutes` is set
1822
(req, res, next) => {

yarn.lock

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,14 @@ core-util-is@~1.0.0:
874874
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
875875
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
876876

877+
cors@^2.8.5:
878+
version "2.8.5"
879+
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
880+
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
881+
dependencies:
882+
object-assign "^4"
883+
vary "^1"
884+
877885
create-ecdh@^4.0.0:
878886
version "4.0.3"
879887
resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.3.tgz#c9111b6f33045c4697f144787f9254cdc77c45ff"
@@ -2326,7 +2334,7 @@ number-is-nan@^1.0.0:
23262334
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
23272335
integrity sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=
23282336

2329-
object-assign@^4.1.0:
2337+
object-assign@^4, object-assign@^4.1.0:
23302338
version "4.1.1"
23312339
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
23322340
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
@@ -3452,6 +3460,11 @@ v8-compile-cache@^2.0.0:
34523460
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.0.2.tgz#a428b28bb26790734c4fc8bc9fa106fccebf6a6c"
34533461
integrity sha512-1wFuMUIM16MDJRCrpbpuEPTUGmM5QMUg0cr3KFwra2XgOgFcPGDQHDh3CszSCD2Zewc/dh/pamNEW8CbfDebUw==
34543462

3463+
vary@^1:
3464+
version "1.1.2"
3465+
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
3466+
integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=
3467+
34553468
34563469
version "0.0.4"
34573470
resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-0.0.4.tgz#5d7ea45bbef9e4a6ff65f95438e0a87c357d5a73"

0 commit comments

Comments
 (0)