Skip to content

Commit 944744a

Browse files
dominiciampogo
authored andcommitted
sdk/node: re-introduce custom baseUrl support
When run outside of a node process (i.e. in the browser), the SEQADDR environment variable is not a consistent method for setting a custom API URL. Closes #4682 Author: Dominic Dagradi <ddagradi@gmail.com> Date: Tue Aug 14 16:39:13 2018 -0700 upstream:b912a75b3497b7b831609684038a21fb592b17da
1 parent b85d8f2 commit 944744a

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# Sequence Node SDK changelog
22

3+
## 2.2.1 (??????)
4+
5+
* Added support for setting a custom API URL when run outside
6+
of a Node process.
7+
38
## 2.2.0 (20180808)
49

510
* Added `updateTags` to `Action`.
6-
* Added support for dynamically addressing different API hosts for
11+
* Added support for dynamically addressing different API hosts for
712
individual ledgers. Internal APIs only, works automatically.
813

914
## 2.1.0 (20180516)

src/connection.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export class Connection {
9393
public retryBaseDelayMs = 40
9494
public retryMaxDelayMs = 20000
9595
public credential?: string
96+
public baseUrl: string
9697
public agent?: Agent
9798
public ledgerName: string
9899
private ledgerUrl: string
@@ -107,6 +108,7 @@ export class Connection {
107108
* @returns {Client}
108109
*/
109110
constructor(ledgerName: string, credential?: string, agent?: Agent) {
111+
this.baseUrl = 'https://' + (process.env.SEQADDR || 'api.seq.com')
110112
this.ledgerName = ledgerName
111113
this.credential = credential
112114
this.agent = agent
@@ -285,7 +287,7 @@ export class Connection {
285287

286288
public async getLedgerUrl() {
287289
const body = (await this.requestRaw(
288-
'https://' + (process.env.SEQADDR || 'api.seq.com') + '/hello',
290+
this.baseUrl + '/hello',
289291
{
290292
ledger_name: this.ledgerName,
291293
},

test/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ describe('Errors', () => {
116116
})
117117

118118
describe('no server', () => {
119-
const unauthedClient = testHelpers.constructClient()
120119
const oldAddr = process.env.SEQADDR
121120

122121
let err: any
@@ -125,6 +124,7 @@ describe('Errors', () => {
125124
process.env.SEQADDR = 'localhost:12345'
126125

127126
try {
127+
const unauthedClient = testHelpers.constructClient()
128128
await unauthedClient.accounts.list().page()
129129
} catch (e) {
130130
err = e

0 commit comments

Comments
 (0)