birdpack 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/method.js +3 -2
- package/lib/server.js +32 -11
- package/lib/websocket.js +5 -1
- package/package.json +1 -1
package/lib/method.js
CHANGED
|
@@ -64,7 +64,7 @@ module.exports = {
|
|
|
64
64
|
return this;
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
|
-
websocket:(app, use, domain)=>{
|
|
67
|
+
websocket:(app, use, {domain, next})=>{
|
|
68
68
|
return (url, a, b, c)=>{
|
|
69
69
|
let typeA = typeof a == 'function';
|
|
70
70
|
let typeB = typeof b == 'function';
|
|
@@ -95,7 +95,8 @@ module.exports = {
|
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
app.setUpgrade({
|
|
98
|
-
domain,
|
|
98
|
+
domain,
|
|
99
|
+
next,
|
|
99
100
|
url,
|
|
100
101
|
callback: app.setCall(callback)
|
|
101
102
|
});
|
package/lib/server.js
CHANGED
|
@@ -87,7 +87,7 @@ module.exports = class{
|
|
|
87
87
|
methodPlugin.basic(this, this, {domain:'*'});
|
|
88
88
|
this.routes = methodPlugin.routes(this);
|
|
89
89
|
this.directory = methodPlugin.directory(this);
|
|
90
|
-
this.websocket = methodPlugin.websocket(this, this, '*');
|
|
90
|
+
this.websocket = methodPlugin.websocket(this, this, {domain:'*'});
|
|
91
91
|
}
|
|
92
92
|
setupSSL(){
|
|
93
93
|
if(this.opt.use !== 'https'){
|
|
@@ -236,13 +236,19 @@ module.exports = class{
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
if(call && call.hasOwnProperty(ws.path)){
|
|
239
|
-
call = call[ws.path]
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
239
|
+
call = call[ws.path];
|
|
240
|
+
|
|
241
|
+
if(call.next !== false){
|
|
242
|
+
this.getCall(call.next)(ws, ()=>{
|
|
243
|
+
const run = this.getCall(call.callback);
|
|
244
|
+
ws.update(run);
|
|
245
|
+
run(ws, 'start');
|
|
246
|
+
});
|
|
247
|
+
}else{
|
|
248
|
+
const run = this.getCall(call.callback);
|
|
249
|
+
ws.update(run);
|
|
250
|
+
run(ws, 'start');
|
|
251
|
+
}
|
|
246
252
|
}else{
|
|
247
253
|
ws.error(404);
|
|
248
254
|
}
|
|
@@ -317,6 +323,7 @@ module.exports = class{
|
|
|
317
323
|
methodPlugin.basic(this, next, {domain, next:this.setCall(n)});
|
|
318
324
|
next.routes = methodPlugin.routes(next);
|
|
319
325
|
next.directory = methodPlugin.directory(next);
|
|
326
|
+
next.websocket = methodPlugin.websocket(this, next, {domain, next:this.setCall(n)});
|
|
320
327
|
|
|
321
328
|
return next;
|
|
322
329
|
}
|
|
@@ -324,7 +331,7 @@ module.exports = class{
|
|
|
324
331
|
methodPlugin.basic(this, config, {domain});
|
|
325
332
|
config.routes = methodPlugin.routes(config);
|
|
326
333
|
config.directory = methodPlugin.directory(config);
|
|
327
|
-
config.websocket = methodPlugin.websocket(this, config, domain);
|
|
334
|
+
config.websocket = methodPlugin.websocket(this, config, {domain});
|
|
328
335
|
|
|
329
336
|
return config;
|
|
330
337
|
}
|
|
@@ -377,7 +384,7 @@ module.exports = class{
|
|
|
377
384
|
this.maps[domain][method].params[mode == 'params' ? 0 : 1].push(route);
|
|
378
385
|
}
|
|
379
386
|
}
|
|
380
|
-
setUpgrade({domain, url, callback}){
|
|
387
|
+
setUpgrade({domain, next, url, callback}){
|
|
381
388
|
if(typeof domain != 'string'){
|
|
382
389
|
domain = '*';
|
|
383
390
|
}
|
|
@@ -390,12 +397,17 @@ module.exports = class{
|
|
|
390
397
|
return false;
|
|
391
398
|
}
|
|
392
399
|
|
|
400
|
+
if(typeof next != 'number'){
|
|
401
|
+
next = false;
|
|
402
|
+
}
|
|
403
|
+
|
|
393
404
|
if(!this.mapws.hasOwnProperty(domain)){
|
|
394
405
|
this.mapws[domain] = {};
|
|
395
406
|
}
|
|
396
407
|
|
|
397
408
|
this.mapws[domain][url] = {
|
|
398
|
-
callback
|
|
409
|
+
callback,
|
|
410
|
+
next,
|
|
399
411
|
};
|
|
400
412
|
}
|
|
401
413
|
setCall(callback){
|
|
@@ -408,5 +420,14 @@ module.exports = class{
|
|
|
408
420
|
}
|
|
409
421
|
return ()=>{};
|
|
410
422
|
}
|
|
423
|
+
next(n){
|
|
424
|
+
let next = {};
|
|
425
|
+
methodPlugin.basic(this, next, {domain:'*', next:this.setCall(n)});
|
|
426
|
+
next.routes = methodPlugin.routes(next);
|
|
427
|
+
next.directory = methodPlugin.directory(next);
|
|
428
|
+
next.websocket = methodPlugin.websocket(this, next, {domain:'*', next:this.setCall(n)});
|
|
429
|
+
|
|
430
|
+
return next;
|
|
431
|
+
}
|
|
411
432
|
}
|
|
412
433
|
|
package/lib/websocket.js
CHANGED
|
@@ -11,6 +11,7 @@ module.exports = class{
|
|
|
11
11
|
query = {}
|
|
12
12
|
method = ''
|
|
13
13
|
ip = ''
|
|
14
|
+
isUID = false
|
|
14
15
|
callback = ()=>{}
|
|
15
16
|
log = ()=>{}
|
|
16
17
|
constructor({req, socket, head}){
|
|
@@ -170,6 +171,7 @@ module.exports = class{
|
|
|
170
171
|
const head = tools.head2line(this.header);
|
|
171
172
|
const statusLine = `HTTP/1.1 ${this.status} ${tools.statusText(this.status)}`;
|
|
172
173
|
const headLine = `${statusLine}\r\n${head}\r\n\r\n`;
|
|
174
|
+
this.isUID = true;
|
|
173
175
|
this.write(Buffer.from(headLine));
|
|
174
176
|
|
|
175
177
|
this.log();
|
|
@@ -177,7 +179,9 @@ module.exports = class{
|
|
|
177
179
|
return this;
|
|
178
180
|
}
|
|
179
181
|
write(data, callback){
|
|
180
|
-
if(this.
|
|
182
|
+
if(!this.isUID){
|
|
183
|
+
this.error(400);
|
|
184
|
+
}else if(this.socket.writable){
|
|
181
185
|
this.socket.write(data, callback);
|
|
182
186
|
}else if(this.req.destroyed){
|
|
183
187
|
this.req.destroy();
|