diff --git a/.eslintrc b/.eslintrc index ececb49..ce8b388 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,7 +9,6 @@ comma-style: [error, last], eol-last: [error, always], import/no-unresolved: off, - import/no-dynamic-require: off, indent: [error, 2, { SwitchCase: 1 }], global-require: off, linebreak-style: [error, unix], diff --git a/README.md b/README.md index 03a550a..4960bf3 100644 --- a/README.md +++ b/README.md @@ -55,15 +55,17 @@ const services = [ 'services/bar.js', ] const options = { - transporter: 'nats', - transporterOptions: { - servers: ['nats://demo.nats.io:4222'], - timeout: 3000, - pingInterval: 120000, - reconnect: true, - reconnectTimeWait: 2000, - maxReconnectAttempts: 10, - maxRequestRetryAttempts: 3, + transporter: { + name: 'nats', + options: { + servers: ['nats://demo.nats.io:4222'], + timeout: 3000, + pingInterval: 120000, + reconnect: true, + reconnectTimeWait: 2000, + maxReconnectAttempts: 10, + maxRequestRetryAttempts: 3, + }, }, } @@ -75,10 +77,17 @@ just pass config to `Broker()` and then run `node services/bar.js`: ```javascript const broker = require('microsia/broker') const app = broker({ - transporter: 'nats', - transporterOptions: { - servers: ['nats://demo.nats.io:4222'], - timeout: 3000, + transporter: { + name: 'nats', + options: { + servers: ['nats://demo.nats.io:4222'], + timeout: 3000, + pingInterval: 120000, + reconnect: true, + reconnectTimeWait: 2000, + maxReconnectAttempts: 10, + maxRequestRetryAttempts: 3, + }, }, }).createService({ name: 'bar' }) diff --git a/example/gateway/index.js b/example/gateway/index.js index be976f6..da85515 100644 --- a/example/gateway/index.js +++ b/example/gateway/index.js @@ -5,10 +5,17 @@ const broker = require('../../broker') // Broker const expressApp = express() const port = 3000 const microApp = broker({ - transporter: 'nats', - transporterOptions: { - servers: ['nats://demo.nats.io:4222'], - timeout: 3000, + transporter: { + name: 'nats', + options: { + servers: ['nats://demo.nats.io:4222'], + timeout: 3000, + pingInterval: 120000, + reconnect: true, + reconnectTimeWait: 2000, + maxReconnectAttempts: 10, + maxRequestRetryAttempts: 3, + }, }, }).createService({ name: 'gateway' }) diff --git a/example/index.js b/example/index.js index 972ca57..0c351b6 100644 --- a/example/index.js +++ b/example/index.js @@ -5,15 +5,17 @@ const services = [ 'services/bar.js', ] const options = { - transporter: 'nats', - transporterOptions: { - servers: ['nats://demo.nats.io:4222'], - timeout: 3000, - pingInterval: 120000, - reconnect: true, - reconnectTimeWait: 2000, - maxReconnectAttempts: 10, - maxRequestRetryAttempts: 3, + transporter: { + name: 'nats', + options: { + servers: ['nats://demo.nats.io:4222'], + timeout: 3000, + pingInterval: 120000, + reconnect: true, + reconnectTimeWait: 2000, + maxReconnectAttempts: 10, + maxRequestRetryAttempts: 3, + }, }, } diff --git a/lib/broker/index.js b/lib/broker/index.js index 945a8b6..6d2fb1b 100644 --- a/lib/broker/index.js +++ b/lib/broker/index.js @@ -9,11 +9,12 @@ const TRANSPORTERS = { class Broker { constructor(opt = {}) { try { - this.TransporterClass = require(TRANSPORTERS[opt.transporter]) + // eslint-disable-next-line import/no-dynamic-require, global-require + this.TransporterClass = require(TRANSPORTERS[opt.transporter.name]) } catch (e) { // console.log('No valid trans was given => create only local transporter') } - this.transporterOpt = { ...opt.transporterOptions } + this.transporterOpt = { ...opt.transporter.options } this.transporter = null this.localTransporter = null this.services = new Map() diff --git a/lib/runner.js b/lib/runner.js index a984cee..316b4ff 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -7,6 +7,7 @@ function loadServices(opt, arr) { // Load all given services arr.forEach((service) => { + // eslint-disable-next-line import/no-dynamic-require, global-require require(path.join(process.cwd(), service)) }) }