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

OPTIONS requests from the browser / CORS are not working, getting 405 #26

Closed
JADurham909 opened this issue Dec 21, 2015 · 4 comments
Closed

Comments

@JADurham909
Copy link

This block of code is preventing OPTIONS calls in the cors module from working. The cors fitting middleware is never hit because a 405 is returned in the connect middleware.

      if (!operation) {
        var path = runner.getPath(req);
        if (!path) { return next(); }

        if (!path['x-swagger-pipe']) {
          var msg = util.format('Path [%s] defined in Swagger, but %s operation is not.', path.path, req.method);
          var err = new Error(msg);
          err.statusCode = 405;

          var allowedMethods = _.map(path.operationObjects, function(operation) {
            return operation.method.toUpperCase();
          });
          err.allowedMethods = allowedMethods;

          res.setHeader('Allow', allowedMethods.sort().join(', '));
          return next(err);
        }
      }
@JADurham909
Copy link
Author

This prevents the problem

if (!path['x-swagger-pipe'] && req.method !== 'OPTIONS') {

@JADurham909 JADurham909 changed the title OPTIONS requests from the browser / CORS is not working, getting 405 OPTIONS requests from the browser / CORS are not working, getting 405 Dec 21, 2015
@theganyo
Copy link
Collaborator

@JADurham909 Thanks, Justin! I'll take a look!

@JADurham909
Copy link
Author

Awesome thanks!

@theganyo
Copy link
Collaborator

You bet. FYI, it's pushed to npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants