Commit 9e5ff94708752350082eaa68139aba98915147c3

Authored by Adhidarma Hadiwinoto
1 parent a99d67bf64
Exists in master

Experimental POST-JSON

Showing 2 changed files with 19 additions and 5 deletions Side-by-side Diff

lib/hit/dump-req-res.js
... ... @@ -53,7 +53,11 @@ ${
53 53 )
54 54 }
55 55  
56   -${httpMethod === 'GET' ? `FULL URL: ${endpointUrl}?${querystring.stringify(params)}` : `FORM DATA: ${new URLSearchParams(params).toString()}`}
  56 +${
  57 + (httpMethod === 'GET' && `FULL URL: ${endpointUrl}?${querystring.stringify(params)}`)
  58 + || (httpMethod === 'POST' && `FORM DATA: ${new URLSearchParams(params).toString()}`)
  59 + || ''
  60 +}
57 61  
58 62 RESPONSE-STATUS: ${responseStatus}
59 63 RESPONSE-BODY:
lib/hit/prepaid-topup.js
... ... @@ -59,20 +59,30 @@ module.exports = async (xid, task) => {
59 59 },
60 60 });
61 61  
62   - const response = config.partner.method === 'POST'
63   - ? await axios.post(endpointUrl, new URLSearchParams(params), {
  62 + let response;
  63 + if (config.partner.method === 'POST') {
  64 + response = await axios.post(endpointUrl, new URLSearchParams(params), {
64 65 headers: {
65 66 'User-Agent': 'KOMODO-GW-HTTPGETX',
66 67 },
67 68 timeout: config.partner.hit_timeout_ms || 60 * 1000,
68   - })
69   - : await axios.get(endpointUrl, {
  69 + });
  70 + } else if (config.partner.method === 'POST-JSON') {
  71 + response = await axios.post(endpointUrl, params, {
  72 + headers: {
  73 + 'User-Agent': 'KOMODO-GW-HTTPGETX',
  74 + },
  75 + timeout: config.partner.hit_timeout_ms || 60 * 1000,
  76 + });
  77 + } else {
  78 + response = await axios.get(endpointUrl, {
70 79 headers: {
71 80 'User-Agent': 'KOMODO-GW-HTTPGETX',
72 81 },
73 82 timeout: config.partner.hit_timeout_ms || 60 * 1000,
74 83 params,
75 84 });
  85 + }
76 86  
77 87 if (!response) {
78 88 const e = new Error(`${MODULE_NAME} 8CF4E04D: Empty response`);