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

Document preflight configuration. #563

Open
amaurer opened this issue Jun 11, 2018 · 1 comment
Open

Document preflight configuration. #563

amaurer opened this issue Jun 11, 2018 · 1 comment

Comments

@amaurer
Copy link

@amaurer amaurer commented Jun 11, 2018

Is there any documentation regarding CORS preflight requests? Seems like these should automatically be configured based on the swagger definition.

I'm looking to return the verbs defined in swagger for my resources (paths) but I can't even find how to control "preFlightContinue" option.

Thanks in advance.

@amaurer
Copy link
Author

@amaurer amaurer commented Jun 11, 2018

I just ended up creating a fitting to handling the verbs based off of swagger definition


const _ = require('lodash');
const verbWhitelist = ["get", "post"];


// Used for CORS preflight options by path.
module.exports = function create(fittingDef, bagpipes) {


  return function corsVerbs(context, cb) {
    
    // If not options, go to next controller
    if (context.request.method !== 'OPTIONS') return cb(null, context);
    
    let verbs = _.pick(context.request.swagger.path, verbWhitelist);
    let responseVerbs = Object.keys(verbs).map(function (x) { return x.toUpperCase() });
    if (responseVerbs.indexOf('OPTIONS') === -1) responseVerbs.push('OPTIONS');
    context.response.set('Access-Control-Allow-Methods', responseVerbs.join(','))
    context.response.status(204).send();

  };


};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.