G2A Many GEOs
SHARE
TWEET

Untitled

a guest Apr 10th, 2020 149 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* axios.js */
  2. import axios from 'axios';
  3. import router from '@/router';
  4. import store from '@/store/store'
  5.  
  6. const api =  axios.create({
  7.     baseURL: '/'
  8. });
  9.  
  10. api.interceptors.response.use(
  11.     (res) => {
  12.         return res;
  13.     },
  14.     (error) => {
  15.         const { response }  = error
  16.         if (response.status === 403) {
  17.             store.dispatch('auth/logOut')
  18.             router.replace({ path: '/logout' })
  19.         }
  20.         return response;
  21.     }
  22. );
  23.  
  24. export default api;
  25.  
  26. /* api.js */
  27. import axios from './axios'
  28.  
  29. export default function api(url, queryParams = null, token = null) {
  30.     let headers = buildHeaders(token)
  31.  
  32.     const config = {
  33.         headers,
  34.         ...(!queryParams ? {} : { params: buildParams(queryParams) })
  35.     }
  36.  
  37.     return {
  38.         post: data => axios.post(url, data, config)
  39.             .then(res => res)
  40.             .catch(e => console.error(e)),
  41.  
  42.         get: () => axios.get(url, config)
  43.             .then(res => res)
  44.             .catch(e => console.error(e)),
  45.  
  46.         put: data => axios.put(url, data, config)
  47.             .then(res => res)
  48.             .catch(e => console.error(e)),
  49.            
  50.         delete: () => axios.delete(url, config)
  51.             .then(res => res)
  52.             .catch(e => console.error(e))
  53.     }
  54. }
  55.  
  56. function buildHeaders(token) {
  57.     return {
  58.         'x-requested-with': 'XMLHttpRequest',
  59.         ...(token ? { 'X-CSRF-Token': token } : {})
  60.     }
  61. }
  62.  
  63. /* Example */
  64. const response = await api(`${BASE_URL}/pre-validate`).get()
  65. const response = await api(`${BASE_URL}/set-customer`).post(payload)
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top