Method
constructor
(
public url: string,
public appId: string,
public appSecret: string
)
Source from the content-addressed store, hash-verified
| 8 | loginP: Promise<void>; |
| 9 | |
| 10 | constructor( |
| 11 | public url: string, |
| 12 | public appId: string, |
| 13 | public appSecret: string |
| 14 | ) { |
| 15 | if (!url || !appId || !appSecret) { |
| 16 | throw new Error( |
| 17 | 'Require params: apiUrl, appId, appSecret. You can set it with env' |
| 18 | ); |
| 19 | } |
| 20 | |
| 21 | this.request = axios.create({ |
| 22 | baseURL: url, |
| 23 | }); |
| 24 | this.request.interceptors.request.use(async (val) => { |
| 25 | if ( |
| 26 | this.jwt && |
| 27 | ['post', 'get'].includes(String(val.method).toLowerCase()) && |
| 28 | !val.headers['X-Token'] |
| 29 | ) { |
| 30 | // 任何请求都尝试增加token |
| 31 | val.headers['X-Token'] = this.jwt; |
| 32 | } |
| 33 | |
| 34 | return val; |
| 35 | }); |
| 36 | this.loginP = this.login(); |
| 37 | } |
| 38 | |
| 39 | async login() { |
| 40 | try { |
Callers
nothing calls this directly
Tested by
no test coverage detected