(api, options)
| 9 | const option = { baseURL: mockURL } |
| 10 | |
| 11 | function createApi(api, options) { |
| 12 | const obj = parseQueryString(window.location.href) |
| 13 | let url = api |
| 14 | if (obj.key) { |
| 15 | url = `${api}?key=${obj.key}` |
| 16 | if (obj.sourceName) { |
| 17 | url = `${api}?key=${obj.key}&sourceName=${obj.sourceName}` |
| 18 | } |
| 19 | } |
| 20 | return ((api, opts) => { |
| 21 | let baseConfig = { |
| 22 | url: '/', |
| 23 | method: 'post', |
| 24 | baseURL: '', |
| 25 | headers: { |
| 26 | 'Content-Type': 'text/plain', |
| 27 | }, |
| 28 | params: {}, |
| 29 | data: {}, |
| 30 | timeout: '', |
| 31 | withCredentials: true, |
| 32 | responseType: 'json', |
| 33 | validateStatus(status) { |
| 34 | return status >= 200 && status < 300 |
| 35 | }, |
| 36 | } |
| 37 | baseConfig = { ...baseConfig, timeout: 30000, baseURL: mockURL } |
| 38 | |
| 39 | return (...rest) => { |
| 40 | const data = rest[0] || {} |
| 41 | const token = sessionStorage.getItem('token') |
| 42 | if (token) { |
| 43 | // data.token = token |
| 44 | } |
| 45 | let success = null |
| 46 | let failure = null |
| 47 | let config = null |
| 48 | for (let i = 1; i < rest.length; i += 1) { |
| 49 | if (typeof rest[i] === 'function') { |
| 50 | if (!success) { |
| 51 | success = rest[i] |
| 52 | } else { |
| 53 | failure = rest[i] |
| 54 | } |
| 55 | } |
| 56 | if (Object.prototype.toString.call(rest[i]) === '[object Object]') { |
| 57 | config = rest[i] |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | const hooks = { |
| 62 | abort: null, |
| 63 | } |
| 64 | |
| 65 | const cancelToken = new CancelToken((c) => { hooks.abort = c }) |
| 66 | |
| 67 | if (opts && (opts.baseURL.indexOf('12602') !== -1)) { |
| 68 | baseConfig.withCredentials = false |
no test coverage detected