File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,14 +13,12 @@ const METHOD_OFFSET = '/api/'.length;
1313
1414const clients = new Map ( ) ;
1515
16- const receiveArgs = async req => new Promise ( resolve => {
17- const body = [ ] ;
16+ const receiveBody = async req => new Promise ( resolve => {
17+ const buffers = [ ] ;
1818 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 ( ) ) ;
2422 } ) ;
2523} ) ;
2624
@@ -58,8 +56,9 @@ const listener = (req, res) => {
5856 client . error ( 403 , new Error ( `Forbidden: ${ url } ` ) ) ;
5957 return ;
6058 }
61- receiveArgs ( req ) . then ( args => {
59+ receiveBody ( req ) . then ( body => {
6260 const method = url . substring ( METHOD_OFFSET ) ;
61+ const args = JSON . parse ( body ) ;
6362 client . rpc ( method , args ) ;
6463 } ) ;
6564 } else {
You can’t perform that action at this time.
0 commit comments