http.ts 677 字节
Newer Older
X
init  
xjh22222228 已提交
1 2
// Copyright @ 2018-2021 xiejiahe. All rights reserved. MIT license.

X
xjh22222228 已提交
3
import axios from 'axios'
X
init  
xjh22222228 已提交
4 5 6
import { getToken } from '../utils/user'

const httpInstance = axios.create({
X
xjh22222228 已提交
7
  timeout: 60000 * 3,
X
init  
xjh22222228 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
  baseURL: 'https://api.github.com'
})
const token = getToken()

Object.setPrototypeOf(httpInstance, axios)

httpInstance.interceptors.request.use(function (config) {
  config.headers = {
    Authorization: `token ${token}`,
    ...config.headers
  }

  return config
}, function (error) {
  return Promise.reject(error)
})


httpInstance.interceptors.response.use(function (res) {

  return res
}, function (error) {
  return Promise.reject(error)
})

export default httpInstance