Skip to content

Instantly share code, notes, and snippets.

@evanxg852000
Created December 18, 2018 09:17
Show Gist options
  • Save evanxg852000/691a08e41f49215ac7cef45a6daadf09 to your computer and use it in GitHub Desktop.
Save evanxg852000/691a08e41f49215ac7cef45a6daadf09 to your computer and use it in GitHub Desktop.
class Router {
...
route(specs, methods, handlers){
if(this._prefix !== ''){
specs = `${this._prefix}/${specs}`
}
handlers = this._cleanHandlers(handlers)
this._routes.push({
methods,
...this._patternToRegex(specs),
handlers
})
}
group(prefix, fn){
this._prefix = prefix
fn(this)
this._prefix = ''
}
all(specs, handlers){
this.route(specs, ['GET', 'POST', 'PUT', 'DELETE'], handlers)
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment