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

Proxying request from another express server instance

Open Ferk opened this issue 12 years ago • 1 comments

I'm trying to have the tty.js web interface running in a different path of my already existing express server, something like "http://localhost/mypath/ssh".

I don't want to leave any extra port open where people can see I have some other extra service. I would like to use this path without a local network proxy to another port.

I'm doing something like this:

const sshpath = "/mypath/ssh";

console.log("Starting tty SSH web interface");
var ttyserver = require('tty.js').createServer({
    "shell": "sh",
    "port": 8000,
    "localOnly": false,
    "users": {
        "test": "test"
        }
});

var app = require("express")();
var server = require('http').createServer(app);
server.listen(8080);
console.log("... started webserver at 8080 ");

app.use(function(req, res, next)
        {
            if (req.originalUrl.indexOf(sshpath) == 0)
            {
                req.originalUrl = req.originalUrl.replace(sshpath,"/");
                console.log("Access to SSH web interface");
                return ttyserver.emit("request",req, res);  
            }
            else
            {
                return next();  
            }
        });

After accessing the URL "htp://localhost:8080/mypath/ssh" I successfully get the prompt to introduce my username and password. However, afterwards I obtain a "Cannot GET /" page. Am I missing something? looks like the ./static/index.html is not being found.

Also if I go to "htp://localhost:8080/mypath/ssh/options.js" I get a "Cannot GET /options.js", which is different from what it's supposed to happen in tty.js (should show the javascript to apply terminal options).

It works however, if I set the "sshpath" variable to "/" and I access "localhost:8080" but this of course defeats the point.

Ferk avatar Nov 29 '13 13:11 Ferk

Are you concerned about other users on the same server seeing the extra service? If you have a service that is only listening on the localhost address, then it will not accept connections from a non-local address.

I run a handful of web applications on localhost:####, and unify them with a reverse proxy server(*). The reverse proxy is the only application that's actually listening to a public address, and therefore the only port that appears open from the outside.

I've read that some people listen on a named pipe and proxy from there although I've not done that.

(* I formerly used node-http-proxy, but websocket support is currently broken, so I now use nginx instead.)

risacher avatar Dec 07 '13 04:12 risacher