Skip to content

Commit

Permalink
scan api pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Feb 22, 2024
1 parent a6786f5 commit 450dcc2
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions apps/whale-api/src/e2e.defid.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,16 @@ class DefidOceanApiClient {
constructor (protected readonly options: WhaleApiClientOptions) {
this.options = {
// default
url: '',
url: '`http://127.0.0.1:3002', // DEFAULT_OCEAN_ARCHIVE_PORT: 3002
timeout: 60000,
version: '0',
version: 'v0',
network: 'regtest',
...options
}
}

async get (path: string): Promise<any> {
// TODO(canonbrother): endpoint should include `version` and `network`
// const { url: urlString, version, network, timeout } = this.options
// const url = `${urlString as string}/${version as string}/${network as string}/${path}`

const res = await this.fetchTimeout(`${this.options.url}/${path}`, {
const res = await this.fetchTimeout(path, {
method: 'GET',
headers: {
connection: 'open'
Expand All @@ -105,7 +102,7 @@ class DefidOceanApiClient {
}

async post (path: string, body?: any): Promise<any> {
const res = await this.fetchTimeout(`${this.options.url}/${path}`, {
const res = await this.fetchTimeout(path, {
method: 'POST',
headers: {
'content-type': 'application/json',
Expand All @@ -117,11 +114,13 @@ class DefidOceanApiClient {
}

private async fetchTimeout (path: string, init: RequestInit): Promise<Response> {
const timeout = this.options.timeout ?? 60000
const { url: endpoint, version, network, timeout } = this.options
const url = `${endpoint}/${version}/${network}/${path}`

const controller = new AbortController()
const id = setTimeout(() => controller.abort(), timeout)

const req = fetch(path, {
const req = fetch(url, {
cache: 'no-cache',
signal: controller.signal,
keepalive: true,
Expand Down

0 comments on commit 450dcc2

Please sign in to comment.