Created
December 18, 2018 09:17
-
-
Save evanxg852000/691a08e41f49215ac7cef45a6daadf09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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