Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
masterTimeout: 60000,
log: (process.env.COTE_LOG ? true : false),
basePort: (process.env.BASE_PORT ? Number(process.env.BASE_PORT) : 10000),
highestPort: (process.env.HIGHEST_PORT ? Number(process.env.HIGHEST_PORT) : 20000)
}, options.cote)
app.distributionOptions = Object.assign({
publicationDelay: (process.env.PUBLICATION_DELAY ? Number(process.env.PUBLICATION_DELAY) : 10000),
coteDelay: (process.env.COTE_DELAY ? Number(process.env.COTE_DELAY) : undefined),
middlewares: {},
publishEvents: true
}, options)
debug('Initializing feathers-distributed with options', app.distributionOptions)
// Change default base/highest port for automated port finding
portfinder.basePort = app.coteOptions.basePort
portfinder.highestPort = app.coteOptions.highestPort
// We need to uniquely identify the app to avoid infinite loop by registering our own services
app.uuid = uuid()
// Setup cote with options and required delay
if (app.distributionOptions.coteDelay) setTimeout(_ => { initializeCote(app) }, app.distributionOptions.coteDelay)
else initializeCote(app)
// We replace the use method to inject service publisher/responder
const superUse = app.use
app.use = function () {
const path = arguments[0]
// Register the service normally first
const superReturn = superUse.apply(app, arguments)
// Check if cote has already been initialized
if (!app.cote) return superReturn
// With express apps we can directly register middlewares: not supported
if (typeof path !== 'string') return superReturn
export default async port => {
if (port) {
return port;
}
if (process.env.PORT) {
return parseInt(process.env.PORT, 10);
}
portfinder.basePort = parseInt(process.env.BASE_PORT) || 8000;
portfinder.highestPort = portfinder.basePort + 1000;
return portfinder.getPortPromise();
};
const getAvailablePort = async () => {
portfinder.basePort = 8888;
portfinder.highestPort = 9999;
return await portfinder.getPortPromise();
};