Options http method missing in http_methods.js
Opened this issue · 2 comments
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!
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
});
would be great if this feature is implemented in next version