forked from msgbyte/tailchat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin-next): add message and group list
- Loading branch information
1 parent
5bd9b48
commit 65e7cfe
Showing
5 changed files
with
146 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import axios from 'axios'; | ||
import { authStorageKey } from './auth'; | ||
import _set from 'lodash/set'; | ||
import { fetchJSON } from 'tushan'; | ||
|
||
/** | ||
* 创建请求实例 | ||
*/ | ||
function createRequest() { | ||
const ins = axios.create({ | ||
baseURL: '/admin/api', | ||
}); | ||
|
||
ins.interceptors.request.use(async (val) => { | ||
try { | ||
const { token } = JSON.parse( | ||
window.localStorage.getItem(authStorageKey) ?? '{}' | ||
); | ||
_set(val, ['headers', 'Authorization'], `Bearer ${token}`); | ||
|
||
return val; | ||
} catch (err) { | ||
throw err; | ||
} | ||
}); | ||
|
||
return ins; | ||
} | ||
|
||
export const request = createRequest(); | ||
|
||
export const httpClient: typeof fetchJSON = (url, options = {}) => { | ||
try { | ||
if (!options.headers) { | ||
options.headers = new Headers({ Accept: 'application/json' }); | ||
} | ||
const { token } = JSON.parse( | ||
window.localStorage.getItem(authStorageKey) ?? '{}' | ||
); | ||
(options.headers as Headers).set('Authorization', `Bearer ${token}`); | ||
|
||
return fetchJSON(url, options); | ||
} catch (err) { | ||
return Promise.reject(); | ||
} | ||
}; |