X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Frouter%2Findex.js;h=fd19bdf5192cfd9efd7b4c00023f1ae92265cbd1;hb=8d101705d3394039ddf2d2f3339a5e6ada911579;hp=f0d2d945a53909c327ab1661c54e83e9a6cfe097;hpb=1296167385b38ca226f17c3a87ac2135d53c769b;p=squeep-api-dingus diff --git a/lib/router/index.js b/lib/router/index.js index f0d2d94..fd19bdf 100644 --- a/lib/router/index.js +++ b/lib/router/index.js @@ -7,7 +7,7 @@ const { METHODS: httpMethods } = require('http'); const common = require('../common'); -const { DingusError } = require('../errors'); +const { DingusError, RouterNoPathError, RouterNoMethodError } = require('../errors'); const PathParameter = require('./path-parameter'); // Internal identifiers for route entries. @@ -69,6 +69,12 @@ class Router { } routePath[kPathMethods] = {}; + + Object.defineProperty(routePath, 'path', { + enumerable: false, + value: rawPath, + }); + Object.freeze(routePath); return routePath; } @@ -253,17 +259,17 @@ class Router { const { matchedPath, pathParams } = this._pathFind(pathParts); ctx.params = pathParams; if (matchedPath) { - ctx.matchedPath = matchedPath; + ctx.matchedPath = matchedPath.path; if (method in matchedPath[kPathMethods]) { return matchedPath[kPathMethods][method]; } if ('*' in matchedPath[kPathMethods]) { return matchedPath[kPathMethods]['*']; } - throw new DingusError('NoMethod'); + throw new RouterNoMethodError(); } ctx.unmatchedPath = pathParts; - throw new DingusError('NoPath'); + throw new RouterNoPathError(); }