-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add axios as request lib (#14)
* ci: add axios request test * fix: wrong node env * fix: lint code and pass jest * fix : fix some code style * Update packages/website/src/api/character.ts Co-authored-by: Qingyu Deng <[email protected]> * Update packages/website/src/api/character.ts Co-authored-by: Qingyu Deng <[email protected]> * Update App.tsx * style: remove api map Co-authored-by: Qingyu Deng <[email protected]>
- Loading branch information
Showing
7 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
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,2 @@ | ||
NODE_ENV=production | ||
VITE_APP_ROOT=https://api.bgm.tv |
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,9 @@ | ||
import { request } from './request' | ||
import { CharacterDetail } from '../types/common' | ||
import { AxiosPromise } from 'axios' | ||
|
||
type CharacterId = string; | ||
|
||
export const getCharacterDetail = (characterId:CharacterId):AxiosPromise<CharacterDetail> => { | ||
return request(`/v0/characters/${characterId}`) | ||
} |
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,24 @@ | ||
import axios from 'axios' | ||
|
||
const baseURL = 'https://api.bgm.tv' | ||
export const request = axios.create({ | ||
// baseURL: import.meta.env.VITE_APP_ROOT as string, | ||
// import.meta无法通过jest https://github.com/facebook/jest/issues/4842 可能需要改一下jest配置 | ||
baseURL, | ||
timeout: 6000 // 请求超时时间 | ||
}) | ||
|
||
// 异常拦截处理器 | ||
const errorHandler = (error:any) => { | ||
console.log(error) | ||
|
||
return Promise.reject(error) | ||
} | ||
|
||
request.interceptors.request.use(config => { | ||
return config | ||
}, errorHandler) | ||
|
||
request.interceptors.response.use((response) => { | ||
return response | ||
}, errorHandler) |
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,31 @@ | ||
type infoBox = { | ||
key:string, | ||
value:string | { | ||
k:string | ||
v:string | ||
}[] | ||
}[] | ||
|
||
export type CharacterDetail={ | ||
id: number | ||
name: string | ||
type: number | ||
images: { | ||
large: string | ||
medium: string | ||
small: string | ||
grid: string | ||
}, | ||
summary: string | ||
locked: boolean | ||
infobox: infoBox | ||
gender: string | ||
blooType: number | ||
birthYear: number | ||
birthMon: number | ||
birthDay: number | ||
stat: { | ||
comments: number | ||
collects: number | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
ed8bcfd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: