@midwayjs/bootstrap 3.9.1 → 3.10.0
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/dist/interface.d.ts +2 -2
- package/dist/sticky.js +13 -7
- package/package.json +5 -5
package/dist/interface.d.ts
CHANGED
|
@@ -38,9 +38,9 @@ export interface IForkManager<T> {
|
|
|
38
38
|
isWorkerDead(worker: T): boolean;
|
|
39
39
|
isPrimary(): boolean;
|
|
40
40
|
}
|
|
41
|
-
export
|
|
41
|
+
export type ClusterOptions = ForkOptions & ClusterSettings & {
|
|
42
42
|
sticky?: boolean;
|
|
43
43
|
stickyLoadBalancingMethod?: 'random' | 'round-robin' | 'least-connection';
|
|
44
44
|
};
|
|
45
|
-
export
|
|
45
|
+
export type ThreadOptions = ForkOptions & WorkerOptions;
|
|
46
46
|
//# sourceMappingURL=interface.d.ts.map
|
package/dist/sticky.js
CHANGED
|
@@ -60,10 +60,11 @@ function setupStickyMaster(httpServer, opts = {}) {
|
|
|
60
60
|
socket.destroy();
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
|
-
socket.on('data', buffer => {
|
|
64
|
-
|
|
63
|
+
socket.on('data', (buffer) => {
|
|
64
|
+
let encoding = 'utf-8';
|
|
65
|
+
let data = buffer.toString(encoding);
|
|
65
66
|
if (workerId && connectionId) {
|
|
66
|
-
cluster.workers[workerId].send({ type: 'sticky:http-chunk', data, connectionId }, sendCallback);
|
|
67
|
+
cluster.workers[workerId].send({ type: 'sticky:http-chunk', data, encoding, connectionId }, sendCallback);
|
|
67
68
|
return;
|
|
68
69
|
}
|
|
69
70
|
workerId = computeWorkerId(data);
|
|
@@ -71,11 +72,16 @@ function setupStickyMaster(httpServer, opts = {}) {
|
|
|
71
72
|
data
|
|
72
73
|
.substring(0, data.indexOf('\r\n\r\n'))
|
|
73
74
|
.includes('pgrade: websocket'));
|
|
75
|
+
// avoid binary data toString error
|
|
76
|
+
if (data.startsWith('POST') && data.includes('multipart/form-data')) {
|
|
77
|
+
encoding = 'base64';
|
|
78
|
+
data = buffer.toString('base64');
|
|
79
|
+
}
|
|
74
80
|
socket.pause();
|
|
75
81
|
if (mayHaveMultipleChunks) {
|
|
76
82
|
connectionId = randomId();
|
|
77
83
|
}
|
|
78
|
-
cluster.workers[workerId].send({ type: 'sticky:connection', data, connectionId }, socket, {
|
|
84
|
+
cluster.workers[workerId].send({ type: 'sticky:connection', data, encoding, connectionId }, socket, {
|
|
79
85
|
keepOpen: mayHaveMultipleChunks,
|
|
80
86
|
}, sendCallback);
|
|
81
87
|
});
|
|
@@ -105,7 +111,7 @@ exports.setupStickyMaster = setupStickyMaster;
|
|
|
105
111
|
function setupWorker(io) {
|
|
106
112
|
// store connections that may receive multiple chunks
|
|
107
113
|
const sockets = new Map();
|
|
108
|
-
process.on('message', ({ type, data, connectionId }, socket) => {
|
|
114
|
+
process.on('message', ({ type, data, encoding, connectionId }, socket) => {
|
|
109
115
|
switch (type) {
|
|
110
116
|
case 'sticky:connection':
|
|
111
117
|
if (!socket) {
|
|
@@ -114,7 +120,7 @@ function setupWorker(io) {
|
|
|
114
120
|
return;
|
|
115
121
|
}
|
|
116
122
|
io.httpServer.emit('connection', socket); // inject connection
|
|
117
|
-
socket.emit('data', Buffer.from(data)); // republish first chunk
|
|
123
|
+
socket.emit('data', Buffer.from(data, encoding)); // republish first chunk
|
|
118
124
|
socket.resume();
|
|
119
125
|
if (connectionId) {
|
|
120
126
|
sockets.set(connectionId, socket);
|
|
@@ -126,7 +132,7 @@ function setupWorker(io) {
|
|
|
126
132
|
case 'sticky:http-chunk': {
|
|
127
133
|
const socket = sockets.get(connectionId);
|
|
128
134
|
if (socket) {
|
|
129
|
-
socket.emit('data', Buffer.from(data));
|
|
135
|
+
socket.emit('data', Buffer.from(data, encoding));
|
|
130
136
|
}
|
|
131
137
|
}
|
|
132
138
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/bootstrap",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"description": "midwayjs bootstrap",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@midwayjs/async-hooks-context-manager": "^3.
|
|
24
|
+
"@midwayjs/async-hooks-context-manager": "^3.10.0",
|
|
25
25
|
"@midwayjs/event-bus": "^1.0.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@midwayjs/core": "^3.
|
|
28
|
+
"@midwayjs/core": "^3.10.0",
|
|
29
29
|
"@midwayjs/logger": "^2.15.0",
|
|
30
30
|
"request": "2.88.2",
|
|
31
|
-
"socket.io-client": "4.5.
|
|
31
|
+
"socket.io-client": "4.5.4"
|
|
32
32
|
},
|
|
33
33
|
"author": "Harry Chen <czy88840616@gmail.com>",
|
|
34
34
|
"repository": {
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">=12.11.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "33d28f1a020963404488e866432916fd15c0952c"
|
|
42
42
|
}
|