feat(REST URL): removing default REST URL anti-pattern. Error thrown if URL is not specified at startup

This commit is contained in:
Chris Troutner
2025-11-26 10:55:34 -08:00
parent a1ba2ac2f7
commit 1573e0bc4c
3 changed files with 8 additions and 3 deletions
+1 -1
View File
@@ -10,7 +10,7 @@
],
"main": "src/bch-js.js",
"scripts": {
"test": "c8 mocha --trace-warnings --unhandled-rejections=strict --timeout 30000 test/unit/",
"test": "export RESTURL=http://localhost:5942/v6/ && c8 mocha --trace-warnings --unhandled-rejections=strict --timeout 30000 test/unit/",
"test:integration": "npm run test:integration:local:noauth",
"test:integration:nft": "export RESTURL=https://bchn.fullstack.cash/v6/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 -g '#nft1' test/integration/slp.js",
"test:integration:bchn": "export RESTURL=https://bchn.fullstack.cash/v6/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 test/integration/",
+5 -2
View File
@@ -45,7 +45,6 @@ import Ecash from './ecash.js'
// Indexers
import Electrumx from './electrumx.js'
import PsfSlpIndexer from './psf-slp-indexer.js'
const DEFAULT_REST_API = 'https://api.fullstack.cash/v6/'
class BCHJS {
constructor (config) {
@@ -54,7 +53,11 @@ class BCHJS {
this.restURL = config.restURL
} else if (process.env.RESTURL && process.env.RESTURL !== '') {
this.restURL = process.env.RESTURL
} else this.restURL = DEFAULT_REST_API
} else {
throw new Error(
'REST API URL is required. Provide config.restURL or set the RESTURL environment variable.'
)
}
// Retrieve the Bearer token for simple token authentication.
this.bearerToken = '' // default value.
+2
View File
@@ -534,6 +534,8 @@ class ElectrumX {
*/
async txData (txid) {
try {
console.log('bch-js txData() restURL: ', this.restURL)
// Handle single transaction.
if (typeof txid === 'string') {
const response = await this.axios.get(