File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -13,14 +13,12 @@ const METHOD_OFFSET = '/api/'.length;
13
13
14
14
const clients = new Map ( ) ;
15
15
16
- const receiveArgs = async req => new Promise ( resolve => {
17
- const body = [ ] ;
16
+ const receiveBody = async req => new Promise ( resolve => {
17
+ const buffers = [ ] ;
18
18
req . on ( 'data' , chunk => {
19
- body . push ( chunk ) ;
20
- } ) . on ( 'end' , async ( ) => {
21
- const data = body . join ( '' ) ;
22
- const args = JSON . parse ( data ) ;
23
- resolve ( args ) ;
19
+ buffers . push ( chunk ) ;
20
+ } ) . on ( 'end' , ( ) => {
21
+ resolve ( Buffer . concat ( buffers ) . toString ( ) ) ;
24
22
} ) ;
25
23
} ) ;
26
24
@@ -58,8 +56,9 @@ const listener = (req, res) => {
58
56
client . error ( 403 , new Error ( `Forbidden: ${ url } ` ) ) ;
59
57
return ;
60
58
}
61
- receiveArgs ( req ) . then ( args => {
59
+ receiveBody ( req ) . then ( body => {
62
60
const method = url . substring ( METHOD_OFFSET ) ;
61
+ const args = JSON . parse ( body ) ;
63
62
client . rpc ( method , args ) ;
64
63
} ) ;
65
64
} else {
You can’t perform that action at this time.
0 commit comments