From 331d118aa2014cc9d4423d674cf55e9cdbd10685 Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Sat, 24 Aug 2024 12:35:28 +0800 Subject: [PATCH] fix: remove the need of log in src/index.js node:internal/errors:541 throw error; ^ TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined at Url.parse (node:url:170:3) at Object.urlParse [as parse] (node:url:141:13) at new FtpServer (C:\work\xemu\xemu-bsp-list\ftp-srv\src\index.js:34:24) at startFtpServer (C:\work\xemu\xemu-bsp-list\ftp-srv\bin\index.js:133:21) at Object. (C:\work\xemu\xemu-bsp-list\ftp-srv\bin\index.js:11:1) at Module._compile (node:internal/modules/cjs/loader:1369:14) at Module._extensions..js (node:internal/modules/cjs/loader:1427:10) at Module.load (node:internal/modules/cjs/loader:1206:32) at Module._load (node:internal/modules/cjs/loader:1022:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49 { code: 'ERR_INVALID_ARG_TYPE' } Node.js v20.12.0 --- bin/index.js | 3 ++- src/index.js | 11 ++++------- 2 files changed, 6 insertions(+), 8 deletions(-) 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'); }); }