Skip to content

Commit 331d118

Browse files
committed
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.<anonymous> (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
1 parent 89bd13d commit 331d118

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

bin/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
22

3+
const buyan = require('bunyan');
34
const yargs = require('yargs');
45
const path = require('path');
5-
66
const FtpSrv = require('../src');
77
const errors = require('../src/errors');
88

@@ -131,6 +131,7 @@ function startFtpServer(_state) {
131131
}
132132

133133
const ftpServer = new FtpSrv({
134+
log: buyan.createLogger({name: 'ftp-srv'}),
134135
url: _state.url,
135136
pasv_url: _state.pasv_url,
136137
pasv_min: _state.pasv_min,

src/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const _ = require('lodash');
22
const Promise = require('bluebird');
33
const nodeUrl = require('url');
4-
const buyan = require('bunyan');
54
const net = require('net');
65
const tls = require('tls');
76
const EventEmitter = require('events');
@@ -13,7 +12,6 @@ class FtpServer extends EventEmitter {
1312
constructor(options = {}) {
1413
super();
1514
this.options = Object.assign({
16-
log: buyan.createLogger({name: 'ftp-srv'}),
1715
url: 'ftp://127.0.0.1:21',
1816
pasv_min: 1024,
1917
pasv_max: 65535,
@@ -25,8 +23,7 @@ class FtpServer extends EventEmitter {
2523
greeting: null,
2624
tls: false,
2725
timeout: 0
28-
}, options);
29-
26+
}, _.pickBy(options, v => v !== undefined));
3027
this._greeting = this.setupGreeting(this.options.greeting);
3128
this._features = this.setupFeaturesMessage();
3229

@@ -52,7 +49,7 @@ class FtpServer extends EventEmitter {
5249
socket.once('close', () => {
5350
this.emit('disconnect', {connection, id: connection.id, newConnectionCount: Object.keys(this.connections).length});
5451
})
55-
52+
5653
this.emit('connect', {connection, id: connection.id, newConnectionCount: Object.keys(this.connections).length});
5754

5855
const greeting = this._greeting || [];
@@ -67,7 +64,7 @@ class FtpServer extends EventEmitter {
6764
this.log.error(err, '[Event] error');
6865
this.emit('server-error', {error: err});
6966
});
70-
67+
7168
const quit = _.debounce(this.quit.bind(this), 100);
7269

7370
process.on('SIGTERM', quit);
@@ -138,7 +135,7 @@ class FtpServer extends EventEmitter {
138135
} catch (err) {
139136
this.log.error(err, 'Error closing connection', {id});
140137
}
141-
138+
142139
resolve('Disconnected');
143140
});
144141
}

0 commit comments

Comments
 (0)