Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@t3-oss/env-core": "^0.7.3",
"ajv": "^8.17.1",
"axios": "^1.11.0",
"axios-retry": "^4.5.0",
"basic-auth": "^2.0.1",
"bignumber.js": "^9.3.1",
"bip32": "^4.0.0",
Expand Down
16 changes: 14 additions & 2 deletions core/api/src/services/ipfetcher/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import https from "https"

import axios from "axios"
import axiosRetry from "axios-retry"

import { UnknownIpFetcherServiceError } from "@/domain/ipfetcher"
import { PROXY_CHECK_APIKEY } from "@/config"
Expand All @@ -15,6 +18,16 @@ type Params = {
key?: string
}

export const client = axios.create({
timeout: 2000,
httpsAgent: new https.Agent({ keepAlive: true }),
})
axiosRetry(client, {
retries: 3,
retryDelay: () => 500,
shouldResetTimeout: true,
})

export const IpFetcher = (): IIpFetcherService => {
const fetchIPInfo = async (ip: string): Promise<IPInfo | IpFetcherServiceError> => {
const params: Params = {
Expand All @@ -33,10 +46,9 @@ export const IpFetcher = (): IIpFetcherService => {
}

try {
const { data } = await axios.request({
const { data } = await client.request({
url: `https://proxycheck.io/v2/${ip}`,
params,
timeout: 2000, // ms
})

const proxy = !!(data[ip] && data[ip].proxy && data[ip].proxy === "yes")
Expand Down
5 changes: 2 additions & 3 deletions core/api/test/unit/services/ipfetcher/fetch-ip-info.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import axios from "axios"
import MockAdapter from "axios-mock-adapter"

import { IpFetcher } from "@/services/ipfetcher"
import { IpFetcher, client } from "@/services/ipfetcher"

/* eslint @typescript-eslint/ban-ts-comment: "off" */
// @ts-ignore-next-line no-implicit-any error
let mock

beforeAll(() => {
mock = new MockAdapter(axios)
mock = new MockAdapter(client)
})

afterEach(() => {
Expand Down
Loading
Loading