-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add single axios * add apiRequester singletone * remove unused code
- Loading branch information
Showing
8 changed files
with
113 additions
and
82 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
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,21 @@ | ||
import { APIRequester } from 'initia-l1' | ||
import http from 'http' | ||
import https from 'https' | ||
|
||
class APIRequesterSingleton { | ||
private static instances: { [key: string]: APIRequester } = {} | ||
|
||
private constructor() {} | ||
|
||
public static getInstance(uri: string): APIRequester { | ||
if (!APIRequesterSingleton.instances[uri]) { | ||
APIRequesterSingleton.instances[uri] = new APIRequester(uri, { | ||
httpAgent: new http.Agent({ keepAlive: true }), | ||
httpsAgent: new https.Agent({ keepAlive: true }) | ||
}) | ||
} | ||
return APIRequesterSingleton.instances[uri] | ||
} | ||
} | ||
|
||
export default APIRequesterSingleton |
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,25 @@ | ||
import axios, { AxiosInstance } from 'axios' | ||
import https from 'https' | ||
import http from 'http' | ||
|
||
class AxiosSingleton { | ||
private static instance: AxiosInstance | ||
|
||
private constructor() {} | ||
|
||
public static getInstance(): AxiosInstance { | ||
if (!AxiosSingleton.instance) { | ||
AxiosSingleton.instance = axios.create({ | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'User-Agent': 'initia-rollup' | ||
}, | ||
httpsAgent: new https.Agent({ keepAlive: true }), | ||
httpAgent: new http.Agent({ keepAlive: true }) | ||
}) | ||
} | ||
return AxiosSingleton.instance | ||
} | ||
} | ||
|
||
export default AxiosSingleton |
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