Skip to content

Commit aa8faf3

Browse files
committed
fix: fix handling request options object
1 parent 2a455ae commit aa8faf3

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

lib/Modules.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,25 @@ const logger = require('console-files')
77
// https://github.com/axios/axios
88
const axios = require('axios')
99
// preset axios options
10-
const options = {
11-
'method': 'POST',
12-
'headers': {},
13-
'maxRedirects': 2,
14-
'responseType': 'json',
10+
const baseOptions = {
11+
method: 'POST',
12+
maxRedirects: 2,
13+
responseType: 'json',
1514
// max 1mb
16-
'maxContentLength': 1000000
15+
maxContentLength: 1000000
1716
}
1817

19-
module.exports = (url, body, storeId, bigTimeout, cb) => {
20-
// edit request options
21-
options.url = url
22-
options.headers['X-Store-ID'] = storeId
23-
options.data = body
24-
// wait 10s by default and 30s in some cases
25-
options.timeout = bigTimeout ? 30000 : 10000
18+
module.exports = (url, data, storeId, bigTimeout, cb) => {
19+
// setup request options
20+
const reqOptions = Object.assign({}, baseOptions, {
21+
url,
22+
data,
23+
headers: {
24+
'X-Store-ID': storeId
25+
},
26+
// wait 10s by default and 30s in some cases
27+
timeout: bigTimeout ? 30000 : 10000
28+
})
2629

2730
// log the response status code
2831
const debug = (response) => {
@@ -33,7 +36,7 @@ module.exports = (url, body, storeId, bigTimeout, cb) => {
3336
// run request with axios
3437
// parse promise to callback
3538
// returns the promise
36-
return axios(options)
39+
return axios(reqOptions)
3740

3841
.then(response => {
3942
debug(response)

0 commit comments

Comments
 (0)