tty.js icon indicating copy to clipboard operation
tty.js copied to clipboard

Using the programmatic interface can log the wrong port

Open Page- opened this issue 11 years ago • 3 comments

When calling

var tty = require('tty.js');

var app = tty.createServer({
  shell: 'bash',
}).listen(80, null, function(){});

you get [tty.js] Listening on port 8080. logged, but it is actually listening on port 80.

The reason is that https://github.com/chjj/tty.js/blob/0cee00a7010028dc7f908a921f4161d873f70c17/lib/tty.js#L49 uses self.conf.port but we overrode it with a custom port in the listen call.

Page- avatar Dec 23 '14 14:12 Page-

In order for this to work properly, you're supposed to change port by adding a "port" attribute inside the config.json file. By doing it that way, it should also change the message written to the terminal https://github.com/chjj/tty.js/blob/0cee00a7010028dc7f908a921f4161d873f70c17/lib/config.js#L99

thatkookooguy avatar Jul 13 '15 11:07 thatkookooguy

Changing it in the config.json is great if running tty.js directly from the command line, the issue is when calling it from the programmatic interface, for instance you might start multiple tty instances on different ports in order to offer different users or chroots, etc

Page- avatar Jul 13 '15 14:07 Page-

what about doing it like this? this doesn't work?

var app_one = tty.createServer({"port": "1234"});
var app_two = tty.createServer({"port": "4321"});

you can give each createServer a different config file, no? Instead of changing it in the listen command.

inside your example:

var tty = require('tty.js');

var app = tty.createServer({
    shell: 'bash',
    port: 1234,
}).listen();

It works the same as the config.json (and got the same attributes). the config.json is just parsed and passed on in the same way, as can be seen by these two lines from tty.js/bin/tty.js:

var conf = tty.config.readConfig()
 , app = tty.createServer(conf);

thatkookooguy avatar Jul 13 '15 15:07 thatkookooguy