Browse Source

added unroute method

master
mortie 6 years ago
parent
commit
450a0966fb
2 changed files with 21 additions and 2 deletions
  1. 20
    1
      index.js
  2. 1
    1
      package.json

+ 20
- 1
index.js View File

@@ -136,6 +136,7 @@ class App {
* Args:
* method: "GET", "POST", "PUT", "DELETE", "ALL"
* path: path,
* middleware: middleware array (optional)
* func: function(request, response)
*/
route(method, path, middleware, func) {
@@ -144,7 +145,7 @@ class App {
throw new Error("Invalid method.");
}

// Before is optional
// Middleware is optional
if (func === undefined) {
func = middleware;
middleware = undefined;
@@ -186,6 +187,24 @@ class App {
}
}

/*
* Remove a route.
* Args:
* path: path
*/
unroute(path) {
if (path[0] === "^") {
path = "/"+path+"/";
for (var i in this._routes) {
var str = this._routes[i].pattern.toString();
if (path === str)
delete this._routes[i];
}
} else {
delete this._routeMap[path];
}
}

/*
* Add a transform.
* Args:

+ 1
- 1
package.json View File

@@ -1,6 +1,6 @@
{
"name": "webframe",
"version": "0.4.2",
"version": "0.5.0",
"description": "Web framework.",
"main": "index.js",
"scripts": {

Loading…
Cancel
Save