import { URLSearchParams } from 'url' ; import { httpRequest } from '../src/shared/utils' ; param body const encodeBody = ( body ? ) => { if ( body ) { const params = new URLSearchParams ( ) ; Object . keys ( body ) . forEach ( key => { if ( body [ key ] !== undefined ) params . append ( key , body [ key ] ) ; } ) ; return params . toString ( ) ; } } ; export const httpProxy = async ( args ) : Promise < any > => { const { url , method , body , headers } = args ; const formBody = encodeBody ( body ) ; if ( formBody ) { headers [ 'Content-Length' ] = formBody . length . toString ( ) ; } const response = await httpRequest ( url , { method , headers , body : formBody , } ) ; const json = JSON . parse ( response ) ; return json ; } ;