diff --git a/backend/src/api/bisq/bisq.ts b/backend/src/api/bisq/bisq.ts index d0209785b..83e6c318d 100644 --- a/backend/src/api/bisq/bisq.ts +++ b/backend/src/api/bisq/bisq.ts @@ -138,7 +138,7 @@ class Bisq { } private updatePrice() { - axios.get('https://bisq.markets/api/trades/?market=bsq_btc') + axios.get('https://bisq.markets/api/trades/?market=bsq_btc', { timeout: 10000 }) .then((response) => { const prices: number[] = []; response.data.forEach((trade) => { diff --git a/backend/src/api/bitcoin/esplora-api.ts b/backend/src/api/bitcoin/esplora-api.ts index 24220da3e..a98941899 100644 --- a/backend/src/api/bitcoin/esplora-api.ts +++ b/backend/src/api/bitcoin/esplora-api.ts @@ -1,39 +1,42 @@ import config from '../../config'; -import axios from 'axios'; +import axios, { AxiosRequestConfig } from 'axios'; import { AbstractBitcoinApi } from './bitcoin-api-abstract-factory'; import { IEsploraApi } from './esplora-api.interface'; class ElectrsApi implements AbstractBitcoinApi { + axiosConfig: AxiosRequestConfig = { + timeout: 10000, + }; constructor() { } $getRawMempool(): Promise { - return axios.get(config.ESPLORA.REST_API_URL + '/mempool/txids') + return axios.get(config.ESPLORA.REST_API_URL + '/mempool/txids', this.axiosConfig) .then((response) => response.data); } $getRawTransaction(txId: string): Promise { - return axios.get(config.ESPLORA.REST_API_URL + '/tx/' + txId) + return axios.get(config.ESPLORA.REST_API_URL + '/tx/' + txId, this.axiosConfig) .then((response) => response.data); } $getBlockHeightTip(): Promise { - return axios.get(config.ESPLORA.REST_API_URL + '/blocks/tip/height') + return axios.get(config.ESPLORA.REST_API_URL + '/blocks/tip/height', this.axiosConfig) .then((response) => response.data); } $getTxIdsForBlock(hash: string): Promise { - return axios.get(config.ESPLORA.REST_API_URL + '/block/' + hash + '/txids') + return axios.get(config.ESPLORA.REST_API_URL + '/block/' + hash + '/txids', this.axiosConfig) .then((response) => response.data); } $getBlockHash(height: number): Promise { - return axios.get(config.ESPLORA.REST_API_URL + '/block-height/' + height) + return axios.get(config.ESPLORA.REST_API_URL + '/block-height/' + height, this.axiosConfig) .then((response) => response.data); } $getBlock(hash: string): Promise { - return axios.get(config.ESPLORA.REST_API_URL + '/block/' + hash) + return axios.get(config.ESPLORA.REST_API_URL + '/block/' + hash, this.axiosConfig) .then((response) => response.data); } @@ -46,7 +49,7 @@ class ElectrsApi implements AbstractBitcoinApi { } $getRawTransactionBitcoind(txId: string): Promise { - return axios.get(config.ESPLORA.REST_API_URL + '/tx/' + txId) + return axios.get(config.ESPLORA.REST_API_URL + '/tx/' + txId, this.axiosConfig) .then((response) => response.data); } diff --git a/backend/src/api/donations.ts b/backend/src/api/donations.ts index 4f81ba276..580ae3a90 100644 --- a/backend/src/api/donations.ts +++ b/backend/src/api/donations.ts @@ -11,6 +11,7 @@ class Donations { 'Content-Type': 'application/json', 'Authorization': config.SPONSORS.BTCPAY_AUTH, }, + timeout: 10000, }; sponsorsCache: any[] = []; @@ -169,7 +170,8 @@ class Donations { const res = await axios.get(`https://api.twitter.com/1.1/users/show.json?screen_name=${handle}`, { headers: { Authorization: 'Bearer ' + config.SPONSORS.TWITTER_BEARER_AUTH - } + }, + timeout: 10000, }); logger.debug('Twitter user data fetched:' + JSON.stringify(res.data)); return res.data; @@ -177,7 +179,7 @@ class Donations { private async $downloadProfileImageBlob(url: string): Promise { logger.debug('Fetching image blob...'); - const res = await axios.get(url, { responseType: 'arraybuffer' }); + const res = await axios.get(url, { responseType: 'arraybuffer', timeout: 10000 }); logger.debug('Image downloaded.'); return Buffer.from(res.data, 'utf8').toString('base64'); } diff --git a/backend/src/api/fiat-conversion.ts b/backend/src/api/fiat-conversion.ts index 8de9f10bb..7be74f702 100644 --- a/backend/src/api/fiat-conversion.ts +++ b/backend/src/api/fiat-conversion.ts @@ -26,7 +26,7 @@ class FiatConversion { private async updateCurrency(): Promise { try { - const response = await axios.get('https://price.bisq.wiz.biz/getAllMarketPrices'); + const response = await axios.get('https://price.bisq.wiz.biz/getAllMarketPrices', { timeout: 10000 }); const usd = response.data.data.find((item: any) => item.currencyCode === 'USD'); this.conversionRates = { 'USD': usd.price, diff --git a/backend/src/index.ts b/backend/src/index.ts index b0b565741..c4b7045ee 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -202,7 +202,7 @@ class Server { this.app .get(config.MEMPOOL.API_URL_PREFIX + 'donations', async (req, res) => { try { - const response = await axios.get('https://mempool.space/api/v1/donations', { responseType: 'stream' }); + const response = await axios.get('https://mempool.space/api/v1/donations', { responseType: 'stream', timeout: 10000 }); response.data.pipe(res); } catch (e) { res.status(500).end(); @@ -210,7 +210,9 @@ class Server { }) .get(config.MEMPOOL.API_URL_PREFIX + 'donations/images/:id', async (req, res) => { try { - const response = await axios.get('https://mempool.space/api/v1/donations/images/' + req.params.id, { responseType: 'stream' }); + const response = await axios.get('https://mempool.space/api/v1/donations/images/' + req.params.id, { + responseType: 'stream', timeout: 10000 + }); response.data.pipe(res); } catch (e) { res.status(500).end();