Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
evheniy committed Nov 5, 2017
1 parent dcb4ebd commit 066b70d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
42 changes: 28 additions & 14 deletions index.js
Expand Up @@ -54,25 +54,39 @@ module.exports = class {
return {
then(fn) {
routes.push(async (ctx) => {
const paramNames = [];
const parsedUrl = parser.parse(ctx.req.url, true);
const regexp = pathToRegexp(url, paramNames);
if (method === '*' || ctx.req.method.toUpperCase() === method.toUpperCase()) {
if (ctx.req.url === url) {
debug('Router found');
debug('%s %s', ctx.req.method.toUpperCase(), url);

if ((method === '*' || ctx.req.method.toUpperCase() === method.toUpperCase()) && regexp.test(parsedUrl.pathname)) {
debug('Router found');
debug('%s %s', ctx.req.method.toUpperCase(), url);
ctx.request = ctx.request || {};
ctx.request.query = {};
ctx.request.params = {};

ctx.request = ctx.request || {};
ctx.request.query = parsedUrl.query;
ctx.request.params = {};

const captures = parsedUrl.pathname.match(regexp).slice(1);
for (let len = captures.length, i = 0; i < len; i++) {
ctx.request.params[paramNames[i].name] = decodeURIComponent(captures[i]);
return Promise.reject(fn);
}

return Promise.reject(fn);
const paramNames = [];
const parsedUrl = parser.parse(ctx.req.url, true);
const regexp = pathToRegexp(url, paramNames);

if (regexp.test(parsedUrl.pathname)) {
debug('Router found');
debug('%s %s', ctx.req.method.toUpperCase(), url);

ctx.request = ctx.request || {};
ctx.request.query = parsedUrl.query;
ctx.request.params = {};

const captures = parsedUrl.pathname.match(regexp).slice(1);
for (let len = captures.length, i = 0; i < len; i++) {
ctx.request.params[paramNames[i].name] = decodeURIComponent(captures[i]);
}

return Promise.reject(fn);
}
}

return Promise.resolve(ctx);
});

Expand Down
3 changes: 1 addition & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "yeps-router",
"version": "1.1.2",
"version": "1.2.0",
"description": "YEPS promise based router",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -56,7 +56,6 @@
"mocha-lcov-reporter": "^1.3.0",
"npm-run-all": "^4.1.1",
"nsp": "^3.0.0",
"promise-pause-timeout": "^1.0.0",
"rimraf": "^2.6.2",
"yeps": "^1.0.1",
"yeps-error": "^1.2.2",
Expand Down

0 comments on commit 066b70d

Please sign in to comment.