Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CORS configurable by end users #503

Merged
merged 3 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .changeset/93d02184/changes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"releases": [{ "name": "@voussoir/server", "type": "minor" }],
"dependents": [
{ "name": "@voussoir/test-utils", "type": "patch", "dependencies": ["@voussoir/server"] },
{
"name": "@voussoir/cypress-project-access-control",
"type": "patch",
"dependencies": ["@voussoir/test-utils", "@voussoir/server"]
},
{
"name": "@voussoir/cypress-project-basic",
"type": "patch",
"dependencies": ["@voussoir/test-utils", "@voussoir/server"]
},
{
"name": "@voussoir/cypress-project-login",
"type": "patch",
"dependencies": ["@voussoir/test-utils", "@voussoir/server"]
},
{
"name": "@voussoir/cypress-project-twitter-login",
"type": "patch",
"dependencies": ["@voussoir/server"]
}
]
}
1 change: 1 addition & 0 deletions .changeset/93d02184/changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Makes CORS user configurable
8 changes: 7 additions & 1 deletion packages/server/WebServer/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ module.exports = function createGraphQLMiddleware(keystone, { apiPath, graphiqlP
}
},
});
server.applyMiddleware({ app, path: apiPath });
server.applyMiddleware({
app,
path: apiPath,
// Prevent ApolloServer from overriding Keystone's CORS configuration.
// https://www.apollographql.com/docs/apollo-server/api/apollo-server.html#ApolloServer-applyMiddleware
cors: false,
});
if (graphiqlPath) {
app.use(graphiqlPath, (req, res) => {
if (req.user && req.sessionID) {
Expand Down
9 changes: 3 additions & 6 deletions packages/server/WebServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ module.exports = class WebServer {
this.app.use(require('express-pino-logger')(this.config.pinoOptions));
}

this.app.use(
cors({
origin: true,
credentials: true,
})
);
if (this.config.cors) {
this.app.use(cors(this.config.cors));
}

if (this.config.authStrategy) {
// Setup the session as the very first thing.
Expand Down
1 change: 1 addition & 0 deletions packages/server/WebServer/initConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const defaultConfig = {
port: process.env.PORT || 3000,
apiPath: '/admin/api',
graphiqlPath: '/admin/graphiql',
cors: { origin: true, credentials: true },
};

const remapKeys = {
Expand Down