Skip to content

Commit

Permalink
Add rate limiter to fallback API
Browse files Browse the repository at this point in the history
  • Loading branch information
victorkirov committed Oct 28, 2024
1 parent 8e1a4cc commit c10ae9e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api/esplora/esploraAPiProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export class BitcoinEsploraApiProvider {

fallbackBitcoinApi?: AxiosInstance;

fallbackRateLimiter?: AxiosRateLimit;

_network: NetworkType;

constructor(options: EsploraApiProviderOptions) {
Expand Down Expand Up @@ -69,6 +71,11 @@ export class BitcoinEsploraApiProvider {

if (fallbackUrl) {
this.fallbackBitcoinApi = axios.create({ ...axiosConfig, baseURL: fallbackUrl });

this.fallbackRateLimiter = new AxiosRateLimit(this.fallbackBitcoinApi, {
maxRPS: 10,
});

this.bitcoinApi.interceptors.response.use(
// if the request succeeds, we do nothing.
(response) => response,
Expand Down

0 comments on commit c10ae9e

Please sign in to comment.