Skip to content

Commit

Permalink
fix: remove the need of log in src/index.js
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lygstate committed Aug 24, 2024
1 parent 89bd13d commit 331d118
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
3 changes: 2 additions & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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,
Expand Down
11 changes: 4 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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,
Expand All @@ -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();

Expand All @@ -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 || [];
Expand All @@ -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);
Expand Down Expand Up @@ -138,7 +135,7 @@ class FtpServer extends EventEmitter {
} catch (err) {
this.log.error(err, 'Error closing connection', {id});
}

resolve('Disconnected');
});
}
Expand Down

0 comments on commit 331d118

Please sign in to comment.