@@ -7,22 +7,25 @@ const logger = require('console-files')
7
7
// https://github.com/axios/axios
8
8
const axios = require ( 'axios' )
9
9
// 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' ,
15
14
// max 1mb
16
- ' maxContentLength' : 1000000
15
+ maxContentLength : 1000000
17
16
}
18
17
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
+ } )
26
29
27
30
// log the response status code
28
31
const debug = ( response ) => {
@@ -33,7 +36,7 @@ module.exports = (url, body, storeId, bigTimeout, cb) => {
33
36
// run request with axios
34
37
// parse promise to callback
35
38
// returns the promise
36
- return axios ( options )
39
+ return axios ( reqOptions )
37
40
38
41
. then ( response => {
39
42
debug ( response )
0 commit comments