Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
feat: 新增可配DEV_HOST以方便开发前后端分离调试
Browse files Browse the repository at this point in the history
  • Loading branch information
hansthrun authored and smartcatboy committed Feb 17, 2022
1 parent 325f949 commit eb4db72
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// export const DEV_HOST = 'http://0.0.0.0:8000'
export const DEV_HOST = ''
20 changes: 15 additions & 5 deletions src/utils/api.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import axios from 'axios'

import { store } from '../redux/store'
import { DEV_HOST, HOST } from '../config/config'

const host = process.env.NODE_ENV !== 'production' ? DEV_HOST : ''

export const apiRequest = request => axios({
...request,
url: `${host}/api${request.url}`,
});

export const v1Request = request => axios({
...request,
url: `${host}/api/v1${request.url}`
});

export const apiRequest = request => axios({...request, url: `/api${request.url}`});
export const v1Request = request => axios({...request, url: `/api/v1${request.url}`});
export const v1AuthRequest = request => axios({
...request,
url: `/api/v1${request.url}`,
url: `${host}/api/v1${request.url}`,
headers: {...request.headers, Authorization: `Bearer ${store.getState().auth.token}`}
});

export const v2AuthRequest = request => axios({
...request,
url: `/api/v2${request.url}`,
url: `${host}/api/v2${request.url}`,
headers: {...request.headers, Authorization: `Bearer ${store.getState().auth.token}`}
});

0 comments on commit eb4db72

Please sign in to comment.