@@ -24,17 +24,18 @@ module.exports = (routing, port, console) => {
24
24
res . writeHead ( 200 , HEADERS ) ;
25
25
if ( req . method !== 'POST' ) return void res . end ( '"Not found"' ) ;
26
26
const { url, socket } = req ;
27
- const [ place , name , method , id ] = url . substring ( 1 ) . split ( '/' ) ;
27
+ const [ place , name , method ] = url . substring ( 1 ) . split ( '/' ) ;
28
28
if ( place !== 'api' ) return void res . end ( '"Not found"' ) ;
29
29
const entity = routing [ name ] ;
30
30
if ( ! entity ) return void res . end ( '"Not found"' ) ;
31
31
const handler = entity [ method ] ;
32
32
if ( ! handler ) return void res . end ( '"Not found"' ) ;
33
33
const src = handler . toString ( ) ;
34
34
const signature = src . substring ( 0 , src . indexOf ( ')' ) ) ;
35
+ const body = await receiveArgs ( req ) ;
35
36
const args = [ ] ;
36
- if ( signature . includes ( '(id' ) ) args . push ( id ) ;
37
- if ( signature . includes ( '{' ) ) args . push ( await receiveArgs ( req ) ) ;
37
+ if ( signature . includes ( '(id' ) ) args . push ( body . id ) ;
38
+ if ( signature . includes ( '{' ) ) args . push ( ... body ) ;
38
39
console . log ( `${ socket . remoteAddress } ${ method } ${ url } ` ) ;
39
40
const result = await handler ( ...args ) ;
40
41
res . end ( JSON . stringify ( result ) ) ;
0 commit comments