Skip to content

Commit

Permalink
Added a missing controller.params in WebSocket controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
petersirka committed Jan 23, 2018
1 parent f2307a6 commit 64bf279
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
======= 2.9.3


- updated: RESTBuilder default headers are lower-case

- fixed: a missing property `controller.params` in WebSocket controller
- fixed: `$ASYNC()` execution in some cases
- fixed: `SCRIPT()` code with comments
- fixed: a callback reference in `OPERATION()`
Expand Down
27 changes: 24 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2521,16 +2521,20 @@ F.websocket = function(url, funcInitialize, flags, length) {
var regIndex = null;
var hash = url2.hash();
var urlraw = U.path(url2) + (isWILDCARD ? '*' : '');
var params = [];

if (url.indexOf('{') !== -1) {

routeURL.forEach(function(o, i) {

if (o.substring(0, 1) !== '{')
return;

arr.push(i);

var sub = o.substring(1, o.length - 1);
var name = o.substring(1, o.length - 1).trim();

params.push(name);

if (sub[0] !== '/')
return;
Expand All @@ -2544,11 +2548,10 @@ F.websocket = function(url, funcInitialize, flags, length) {
regIndex = [];
}

params[params.length - 1] = 'regexp' + (regIndex.length + 1);
reg[i] = new RegExp(sub.substring(1, index), sub.substring(index + 1));
regIndex.push(i);
});

priority -= arr.length;
}

if (typeof(allow) === 'string')
Expand Down Expand Up @@ -2679,6 +2682,7 @@ F.websocket = function(url, funcInitialize, flags, length) {
r.controller = _controller ? _controller : 'unknown';
r.owner = _owner;
r.url = routeURL;
r.paramnames = params.length ? params : null;
r.param = arr;
r.subdomain = subdomain;
r.priority = priority;
Expand Down Expand Up @@ -12657,6 +12661,23 @@ WebSocket.prototype = {
get secured() {
return this.req.secured;
},

get params() {
if (this.$params)
return this.$params;
var split = framework_internal.routeSplit(this.url, true);
var names = this.route.paramnames;
if (names) {
var obj = {};
for (var i = 0; i < names.length; i++)
obj[names[i]] = split[this.route.param[i]];
this.$params = obj;
return obj;
} else {
this.$params = EMPTYOBJECT;
return EMPTYOBJECT;
}
}
};

WebSocket.prototype.emit = function(name, a, b, c, d, e, f, g) {
Expand Down

0 comments on commit 64bf279

Please sign in to comment.