-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: axios组件结构调整,代码优化 * chore: update --------- Co-authored-by: 142vip <[email protected]>
- Loading branch information
Showing
9 changed files
with
70 additions
and
132 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,6 @@ | ||
/** | ||
* 默认配置 | ||
*/ | ||
export default { | ||
axios: {}, | ||
}; |
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,40 @@ | ||
import { | ||
Config, | ||
Init, | ||
Provide, | ||
Scope, | ||
ScopeEnum, | ||
ServiceFactory, | ||
} from '@midwayjs/core'; | ||
import axios, { AxiosInstance, CreateAxiosDefaults } from 'axios'; | ||
|
||
@Provide() | ||
@Scope(ScopeEnum.Singleton) | ||
export class HttpServiceFactory extends ServiceFactory<AxiosInstance> { | ||
@Config('axios') | ||
axiosConfig: any; | ||
|
||
@Init() | ||
async init() { | ||
let axiosConfig = this.axiosConfig; | ||
if (!this.axiosConfig['clients']) { | ||
axiosConfig = { | ||
default: {}, | ||
clients: { | ||
default: this.axiosConfig, | ||
}, | ||
}; | ||
} | ||
await this.initClients(axiosConfig); | ||
} | ||
public getName(): string { | ||
return 'axios'; | ||
} | ||
|
||
protected async createClient( | ||
config: CreateAxiosDefaults, | ||
clientName: string | ||
): Promise<AxiosInstance> { | ||
return axios.create(config); | ||
} | ||
} |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
{ | ||
"name": "base-app", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
} | ||
"dependencies": {} | ||
} |
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