diff --git a/bin/index.js b/bin/index.js index 4466127e..f7bc2b6d 100755 --- a/bin/index.js +++ b/bin/index.js @@ -1,8 +1,8 @@ #!/usr/bin/env node +const buyan = require('bunyan'); const yargs = require('yargs'); const path = require('path'); - const FtpSrv = require('../src'); const errors = require('../src/errors'); @@ -131,6 +131,7 @@ function startFtpServer(_state) { } const ftpServer = new FtpSrv({ + log: buyan.createLogger({name: 'ftp-srv'}), url: _state.url, pasv_url: _state.pasv_url, pasv_min: _state.pasv_min, diff --git a/src/index.js b/src/index.js index 859540df..bcb6362d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,6 @@ const _ = require('lodash'); const Promise = require('bluebird'); const nodeUrl = require('url'); -const buyan = require('bunyan'); const net = require('net'); const tls = require('tls'); const EventEmitter = require('events'); @@ -13,7 +12,6 @@ class FtpServer extends EventEmitter { constructor(options = {}) { super(); this.options = Object.assign({ - log: buyan.createLogger({name: 'ftp-srv'}), url: 'ftp://127.0.0.1:21', pasv_min: 1024, pasv_max: 65535, @@ -25,8 +23,7 @@ class FtpServer extends EventEmitter { greeting: null, tls: false, timeout: 0 - }, options); - + }, _.pickBy(options, v => v !== undefined)); this._greeting = this.setupGreeting(this.options.greeting); this._features = this.setupFeaturesMessage(); @@ -52,7 +49,7 @@ class FtpServer extends EventEmitter { socket.once('close', () => { this.emit('disconnect', {connection, id: connection.id, newConnectionCount: Object.keys(this.connections).length}); }) - + this.emit('connect', {connection, id: connection.id, newConnectionCount: Object.keys(this.connections).length}); const greeting = this._greeting || []; @@ -67,7 +64,7 @@ class FtpServer extends EventEmitter { this.log.error(err, '[Event] error'); this.emit('server-error', {error: err}); }); - + const quit = _.debounce(this.quit.bind(this), 100); process.on('SIGTERM', quit); @@ -138,7 +135,7 @@ class FtpServer extends EventEmitter { } catch (err) { this.log.error(err, 'Error closing connection', {id}); } - + resolve('Disconnected'); }); }