Skip to content

Commit

Permalink
refactor: extract requests to src/apis
Browse files Browse the repository at this point in the history
  • Loading branch information
xianshenglu committed Nov 21, 2020
1 parent 3e9bc38 commit 2ef3100
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/apis/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Axios from 'axios'

export function getApiInfo(origin, params) {
return Axios({
url: `${origin}/api/interface/get`,
method: 'GET',
params,
})
}
10 changes: 10 additions & 0 deletions src/apis/request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Axios from 'axios'

const instance = Axios.create({
withCredentials: true,
headers: {
accept: 'application/json',
},
})

export default instance
11 changes: 2 additions & 9 deletions src/inject/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'
import CodeGen from './codeGen'

import { API_FORMATTER_STR, API_ORIGIN } from '../constants'
import { getApiInfo } from '../apis'

// eslint-disable-next-line no-unused-vars
function hyphenToPascal(str) {
Expand All @@ -21,14 +21,7 @@ function init(config) {
name: '获取 API 代码',
request: () => {
const id = window.location.pathname.split('/').slice(-1)[0]
return axios({
url: `${apiOrigin}/api/interface/get?id=${id}`,
headers: {
accept: 'application/json',
},
method: 'GET',
withCredentials: true,
})
return getApiInfo(apiOrigin, { id })
},
// eslint-disable-next-line no-new-func
formatter: new Function('data', apiFormatterStr),
Expand Down

0 comments on commit 2ef3100

Please sign in to comment.