-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add axios request test #14
Merged
+114
−2
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
46d46f9
ci: add axios request test
8bb88a9
Merge remote-tracking branch 'upstream/master'
0e41aaf
fix: wrong node env
ecb4422
fix: lint code and pass jest
1c65584
fix : fix some code style
72d9371
Merge remote-tracking branch 'upstream/master'
1e064f0
Update packages/website/src/api/character.ts
2a3ed49
Update packages/website/src/api/character.ts
6a601fa
Update App.tsx
814dd38
style: remove api map
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
console.log
好像不太必要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.
请求异常先log一下,以后再补异常处理