fix(bch-js): Selecting custom server when not using JWT token

This commit is contained in:
Chris Troutner
2021-09-08 14:00:00 -07:00
parent fc94041d17
commit 9fe822024c
+28 -26
View File
@@ -5,53 +5,55 @@
*/
// Public NPM libraries
const BCHJS = require('@psf/bch-js')
const BCHJS = require("@psf/bch-js");
// Load individual adapter libraries.
const IPFSAdapter = require('./ipfs')
const LocalDB = require('./localdb')
const LogsAPI = require('./logapi')
const Passport = require('./passport')
const Nodemailer = require('./nodemailer')
const IPFSAdapter = require("./ipfs");
const LocalDB = require("./localdb");
const LogsAPI = require("./logapi");
const Passport = require("./passport");
const Nodemailer = require("./nodemailer");
// const { wlogger } = require('./wlogger')
const JSONFiles = require('./json-files')
const FullStackJWT = require('./fullstack-jwt')
const JSONFiles = require("./json-files");
const FullStackJWT = require("./fullstack-jwt");
const config = require('../../config')
const config = require("../../config");
class Adapters {
constructor (localConfig = {}) {
constructor(localConfig = {}) {
// Encapsulate dependencies
this.ipfs = new IPFSAdapter()
this.localdb = new LocalDB()
this.logapi = new LogsAPI()
this.passport = new Passport()
this.nodemailer = new Nodemailer()
this.jsonFiles = new JSONFiles()
this.bchjs = new BCHJS()
this.config = config
this.ipfs = new IPFSAdapter();
this.localdb = new LocalDB();
this.logapi = new LogsAPI();
this.passport = new Passport();
this.nodemailer = new Nodemailer();
this.jsonFiles = new JSONFiles();
this.bchjs = new BCHJS();
this.config = config;
// Get a valid JWT API key and instance bch-js.
this.fullStackJwt = new FullStackJWT(config)
this.fullStackJwt = new FullStackJWT(config);
}
async start () {
async start() {
try {
if (this.config.getJwtAtStartup) {
// Get a JWT token and instantiate bch-js with it. Then pass that instance
// to all the rest of the apps controllers and adapters.
await this.fullStackJwt.getJWT()
await this.fullStackJwt.getJWT();
// Instantiate bch-js with the JWT token, and overwrite the placeholder for bch-js.
this.bchjs = await this.fullStackJwt.instanceBchjs()
this.bchjs = await this.fullStackJwt.instanceBchjs();
} else {
this.bchjs = new BCHJS({ restURL: this.config.apiServer });
}
// Start the IPFS node.
await this.ipfs.start({ bchjs: this.bchjs })
await this.ipfs.start({ bchjs: this.bchjs });
} catch (err) {
console.error('Error in adapters/index.js/start()')
throw err
console.error("Error in adapters/index.js/start()");
throw err;
}
}
}
module.exports = Adapters
module.exports = Adapters;