Skip to content

Commit

Permalink
feat: passthrough cors middleware if pre-existing headers are present
Browse files Browse the repository at this point in the history
Resolves #447
  • Loading branch information
panva committed Apr 5, 2019
1 parent ab08cbe commit 6ec09ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/helpers/initialize_app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const assert = require('assert');
const querystring = require('querystring');

const cors = require('@koa/cors');

const Router = require('../router');
const { homepage, version } = require('../../package.json');
Expand All @@ -10,6 +9,7 @@ const {
getIntrospection, discovery, checkSession, endSession, codeVerification,
} = require('../actions');
const getInteraction = require('../actions/interaction');
const cors = require('../shared/cors');
const grants = require('../actions/grants');
const responseModes = require('../response_modes');
const error = require('../shared/error_handler');
Expand Down
15 changes: 15 additions & 0 deletions lib/shared/cors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const cors = require('@koa/cors');

module.exports = (opts) => {
const builtin = cors(opts);

return (ctx, next) => {
const headers = Object.keys(ctx.response.headers);

if (headers.find(x => x.toLowerCase().startsWith('access-control-'))) {
return next();
}

return builtin(ctx, next);
};
};

0 comments on commit 6ec09ef

Please sign in to comment.