Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
19 lines (15 sloc) 737 Bytes
_ = require 'underscore'
class Route
constructor: (method, template_string, action) ->
@method = method.toUpperCase()
@template = new RegExp(template_string.replace /\$/g, '(.+)')
@action = action
matches: (request) ->
(@tokens = request.url.match(@template)) and request.method == @method
class Router
constructor: -> @routes = []
get: (template_string, action) -> @routes.push new Route('GET', template_string, action)
post: (template_string, action) -> @routes.push new Route('POST', template_string, action)
delete: (template_string, action) -> @routes.push new Route('DELETE', template_string, action)
route_for: (request) -> _.find @routes, (route) -> route.matches request
exports.Router = Router
Jump to Line
Something went wrong with that request. Please try again.