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 http method missing in http_methods.js #1557

Open
mtrunkat opened this issue Dec 6, 2016 · 2 comments
Open

Options http method missing in http_methods.js #1557

mtrunkat opened this issue Dec 6, 2016 · 2 comments

Comments

@mtrunkat
Copy link

mtrunkat commented Dec 6, 2016

List of http methods -

https://github.com/iron-meteor/iron-router/blob/devel/lib/http_methods.js

contains only the most used (get, post, put, delete, patch). Options method is needed for browser preflight request, see -

https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests .

Is there any reason to don't add it into the iron router?

Currently is possible to implement this method via

Router.route('/route', function() { ..implement everything here.. });

but without having this method in file mentioned above it's not possible to do it in more convenient way

Router
  .route('/route')
  .get(function() { ..one method here.. })
  .patch(function() { ..patch method here.. })

Thanks!

@javascriptlove
Copy link

Was searching for a reason too, apparently it happens that Route has an options property which is/might be used by all the plugins and maybe even on some production services, so that property name is taken. As a temporarily solution, i used something like:

Iron.Route.prototype.on = function(method, fn) {
    // track the method being used for OPTIONS requests.
    this._methods[method] = true;

    this._actionStack.push(this._path, fn, {
        // give each method a unique name so it doesn't clash with the route's
        // name in the action stack
        name: this.getName() + '_' + method.toLowerCase(),
        method: method,

        // for now just make the handler where the same as the route, presumably a
        // server route.
        where: this.handler.where,
        mount: false
    });

    return this;
};
Router.route('myroute', {
  path: '/test',
  where: 'server')
}).on('options', function() {
  // handle your options method here
});

@chrisbutler chrisbutler removed their assignment Feb 11, 2017
@macroramesh6
Copy link

would be great if this feature is implemented in next version

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

No branches or pull requests

4 participants