From b99c95457285e7dc11c01c3bb722576226229528 Mon Sep 17 00:00:00 2001 From: Robin Bron Date: Wed, 7 Jun 2017 15:55:56 +0200 Subject: [PATCH] Added support for the OPTIONS method --- lib/router.js | 6 +++++- src/router.coffee | 14 +++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/router.js b/lib/router.js index d8f8e30..4f5a097 100644 --- a/lib/router.js +++ b/lib/router.js @@ -725,7 +725,8 @@ put: [], patch: [], "delete": [], - any: [] + any: [], + options: [] }; dispatch["static"] = function(pathname, req, res) { var full_path; @@ -1254,6 +1255,9 @@ dispatch.any = function(pattern, callback) { return _pushRoute(pattern, _make_request_wrapper(callback), 'any'); }; + dispatch.options = function(pattern, callback) { + return _pushRoute(pattern, callback, 'options'); + }; dispatch._404 = function(req, res, path) { var default_resp; res.writeHead(404, { diff --git a/src/router.coffee b/src/router.coffee index a8b7d14..89c9ffd 100644 --- a/src/router.coffee +++ b/src/router.coffee @@ -604,12 +604,13 @@ Router = (options = {}) -> # dispatch.routes = - get: [] - post: [] - put: [] - patch: [] + get: [] + post: [] + put: [] + patch: [] delete: [] - any: [] + any: [] + options: [] dispatch.static = (pathname, req, res) -> full_path = "#{dispatch.static_route}#{unescape(pathname)}" @@ -985,6 +986,9 @@ Router = (options = {}) -> dispatch.any = (pattern, callback) -> _pushRoute pattern, _make_request_wrapper(callback), 'any' + dispatch.options = (pattern, callback) -> + _pushRoute pattern, callback, 'options' + dispatch._404 = (req, res, path) ->