Skip to content

Commit 45eafbf

Browse files
committed
v1.0.6
1 parent bdd1508 commit 45eafbf

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "backend-js",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "Backend-js is a layer built above expressjs to enable behaviours framework for nodejs applications.",
55
"main": "index.js",
66
"scripts": {
@@ -49,4 +49,4 @@
4949
},
5050
"homepage": "https://github.com/quaNode/backend-js#readme",
5151
"snyk": true
52-
}
52+
}

src/behaviour.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ var LogBehaviours = {};
5858

5959
var compareRoutes = function (route1, route2) {
6060

61-
var route = (route1 && route1.name && route1.name.indexOf(':') > -1 && route1) || route2;
61+
var route = (route1 && route1.path && route1.path.indexOf(':') > -1 && route1) || route2;
6262
if (route === route2) {
6363

6464
route2 = route1;
6565
route1 = route;
6666
}
67-
if (route && route.name) route = new Route(route.name);
68-
return (route && route.match((route2 && route2.name) || ' ') ||
69-
route1.name === (route2 && route2.name)) &&
67+
if (route && route.path) route = new Route(route.path);
68+
return (route && route.match((route2 && route2.path) || ' ') ||
69+
route1.path === (route2 && route2.path)) &&
7070
(route1.method || '').toLowerCase() === ((route2 && route2.method) || '').toLowerCase();
7171
};
7272

@@ -115,12 +115,12 @@ backend.behaviour = function (path, config) {
115115
throw new Error('Invalid constructor');
116116
}
117117
var named = typeof options.name === 'string' && options.name.length > 0;
118+
var skipSameRoutes;
118119
var unduplicated = function () {
119120

120-
var skipSameRoutes;
121121
if (typeof config === 'object') skipSameRoutes = config.skipSameRoutes;
122-
if (behaviours[options.name] && (typeof skipSameRoutes !== 'boolean' ||
123-
!skipSameRoutes)) throw new Error('Duplicated behavior name: ' + options.name);
122+
if (behaviours[options.name] && skipSameRoutes !== true)
123+
throw new Error('Duplicated behavior name: ' + options.name);
124124
return !behaviours[options.name];
125125
}();
126126
var BehaviourConstructor = define(getConstructor).extend(getLogBehaviour(options, config,
@@ -294,24 +294,26 @@ backend.behaviour = function (path, config) {
294294

295295
return {
296296

297-
name: (behaviours[name] && behaviours[name].path) || name,
297+
name: name,
298+
path: behaviours[name] && behaviours[name].path,
298299
method: behaviours[name] && behaviours[name].method
299300
};
300301
}).filter(function (opt) {
301302

302-
var suffix = opt.name;
303+
var name = opt.name;
304+
var suffix = opt.path;
303305
var method = opt.method;
304306
var route = typeof prefix === 'string' &&
305307
request.path.startsWith(prefix) &&
306308
typeof suffix === 'string' ?
307309
join(prefix, suffix) : suffix || prefix;
308-
return compareRoutes({
310+
return name === options.name && compareRoutes({
309311

310-
name: route,
312+
path: route,
311313
method: method
312314
}, {
313315

314-
name: request.path,
316+
path: request.path,
315317
method: request.method
316318
});
317319
}).length > 0;
@@ -326,15 +328,15 @@ backend.behaviour = function (path, config) {
326328
if (isRoute) {
327329

328330
var keys = Object.keys(behaviours);
329-
if (keys.some(function (key) {
331+
if (!skipSameRoutes && keys.some(function (key) {
330332

331333
return compareRoutes({
332334

333-
name: behaviours[key].path,
335+
path: behaviours[key].path,
334336
method: behaviours[key].method
335337
}, {
336338

337-
name: options.path,
339+
path: options.path,
338340
method: options.method
339341
});
340342
})) throw new Error('Duplicated behavior path: ' + options.path);

0 commit comments

Comments
 (0)