Skip to content

Commit 450dcc2

Browse files
committed
scan api pattern
1 parent a6786f5 commit 450dcc2

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

apps/whale-api/src/e2e.defid.module.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,16 @@ class DefidOceanApiClient {
7878
constructor (protected readonly options: WhaleApiClientOptions) {
7979
this.options = {
8080
// default
81-
url: '',
81+
url: '`http://127.0.0.1:3002', // DEFAULT_OCEAN_ARCHIVE_PORT: 3002
8282
timeout: 60000,
83-
version: '0',
83+
version: 'v0',
84+
network: 'regtest',
8485
...options
8586
}
8687
}
8788

8889
async get (path: string): Promise<any> {
89-
// TODO(canonbrother): endpoint should include `version` and `network`
90-
// const { url: urlString, version, network, timeout } = this.options
91-
// const url = `${urlString as string}/${version as string}/${network as string}/${path}`
92-
93-
const res = await this.fetchTimeout(`${this.options.url}/${path}`, {
90+
const res = await this.fetchTimeout(path, {
9491
method: 'GET',
9592
headers: {
9693
connection: 'open'
@@ -105,7 +102,7 @@ class DefidOceanApiClient {
105102
}
106103

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

119116
private async fetchTimeout (path: string, init: RequestInit): Promise<Response> {
120-
const timeout = this.options.timeout ?? 60000
117+
const { url: endpoint, version, network, timeout } = this.options
118+
const url = `${endpoint}/${version}/${network}/${path}`
119+
121120
const controller = new AbortController()
122121
const id = setTimeout(() => controller.abort(), timeout)
123122

124-
const req = fetch(path, {
123+
const req = fetch(url, {
125124
cache: 'no-cache',
126125
signal: controller.signal,
127126
keepalive: true,

0 commit comments

Comments
 (0)