server actually not working for subdomains #69

Closed
opened 2017-09-29 08:14:14 +00:00 by Freundschaft · 9 comments
Freundschaft commented 2017-09-29 08:14:14 +00:00 (Migrated from github.com)

I just checked the code, and contrary to whats written in the readme (You can set up DNS entries for your domain.tld and *.domain.tld (or sub.domain.tld and *.sub.domain.tld).)

I am not under the impression that the localtunnel server works for sub domains, since in the code, the server always checks for existance of a subdomain in the request, and if so, tries to associate a client session, thus failing all requests that try to do registration api status, etc. can someone confirm this behaviour?

I just checked the code, and contrary to whats written in the readme (You can set up DNS entries for your domain.tld and *.domain.tld (or sub.domain.tld and *.sub.domain.tld).) I am not under the impression that the localtunnel server works for sub domains, since in the code, the server always checks for existance of a subdomain in the request, and if so, tries to associate a client session, thus failing all requests that try to do registration api status, etc. can someone confirm this behaviour?
tmsf commented 2017-09-29 14:45:34 +00:00 (Migrated from github.com)

No it doesn't. This fork by @whitecolor does. I recall that he made a PR ages ago, but was not merged yet.

No it doesn't. This [fork](https://github.com/whitecolor/localtunnel-server) by @whitecolor does. I recall that he made a PR ages ago, but was not merged yet.
Freundschaft commented 2017-09-29 16:25:54 +00:00 (Migrated from github.com)

thanks! is the repository still maintained?

thanks! is the repository still maintained?
Spown commented 2017-12-25 00:37:04 +00:00 (Migrated from github.com)

eyep, doesn't work. The client (under Win10x64) throws an error:

> lt --host http://sub.someserver.com/ -l 127.0.1.1 -p 80
%APPDATA%\Roaming\npm\node_modules\localtunnel\bin\client:48
        throw err;
        ^

Error: localtunnel server returned an error, please try again
    at Request._callback (%APPDATA%\Roaming\npm\node_modules\localtunnel\lib\Tunnel.js:53:27)
    at Request.self.callback (%APPDATA%\Roaming\npm\node_modules\localtunnel\node_modules\request\request.js:188:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:194:7)
    at Request.<anonymous> (%APPDATA%\Roaming\npm\node_modules\localtunnel\node_modules\request\request.js:1171:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:191:7)
    at IncomingMessage.<anonymous> (%APPDATA%\Roaming\npm\node_modules\localtunnel\node_modules\request\request.js:1091:12)
    at Object.onceWrapper (events.js:293:19)
    at emitNone (events.js:91:20)

The server itself doesn't seem to react to the request (it does serve 404 when accessed directly, however), the only line in the output:

2017-12-25T00:08:25.434Z localtunnel server listening on port: 4001

NGINX config:

upstream localtunnel-server-subdomain {
    server 127.0.0.1:4001;
}

server {
        listen 80;
        server_tokens off;
        server_name sub.someserver.com *.sub.someserver.com;

        root /var/opt/localtunnel-subdomain;
        index index.html index.htm;

        location / {
                proxy_pass http://localhost:4001;

                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Proto http;
                proxy_set_header X-NginX-Proxy true;
                proxy_set_header Upgrade $http_upgrade;
                proxy_redirect off;
        }

}

The same installation listening from a root domain works fine.

If you are not going to fix it, at least remove the example from the Readme that indicates it can work on a subdomain and tell people to run it only from root.

eyep, doesn't work. The client (under Win10x64) throws an error: ``` > lt --host http://sub.someserver.com/ -l 127.0.1.1 -p 80 %APPDATA%\Roaming\npm\node_modules\localtunnel\bin\client:48 throw err; ^ Error: localtunnel server returned an error, please try again at Request._callback (%APPDATA%\Roaming\npm\node_modules\localtunnel\lib\Tunnel.js:53:27) at Request.self.callback (%APPDATA%\Roaming\npm\node_modules\localtunnel\node_modules\request\request.js:188:22) at emitTwo (events.js:106:13) at Request.emit (events.js:194:7) at Request.<anonymous> (%APPDATA%\Roaming\npm\node_modules\localtunnel\node_modules\request\request.js:1171:10) at emitOne (events.js:96:13) at Request.emit (events.js:191:7) at IncomingMessage.<anonymous> (%APPDATA%\Roaming\npm\node_modules\localtunnel\node_modules\request\request.js:1091:12) at Object.onceWrapper (events.js:293:19) at emitNone (events.js:91:20) ``` The server itself doesn't seem to react to the request (it does serve 404 when accessed directly, however), the only line in the output: ``` 2017-12-25T00:08:25.434Z localtunnel server listening on port: 4001 ``` NGINX config: ``` upstream localtunnel-server-subdomain { server 127.0.0.1:4001; } server { listen 80; server_tokens off; server_name sub.someserver.com *.sub.someserver.com; root /var/opt/localtunnel-subdomain; index index.html index.htm; location / { proxy_pass http://localhost:4001; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto http; proxy_set_header X-NginX-Proxy true; proxy_set_header Upgrade $http_upgrade; proxy_redirect off; } } ``` The same installation listening from a root domain works fine. If you are not going to fix it, at least remove the example from the Readme that indicates it can work on a subdomain and tell people to run it only from root.
Spown commented 2017-12-25 01:05:06 +00:00 (Migrated from github.com)

@whitecolor's fork is broken as well btw.

@whitecolor's fork is broken as well btw.
phonicmouse commented 2018-01-18 22:15:48 +00:00 (Migrated from github.com)

@Spown @whitecolor's fork works for me...it's just not up to date.

@Spown @whitecolor's fork works for me...it's just not up to date.
William-An commented 2018-03-03 03:20:13 +00:00 (Migrated from github.com)

Yes it still doesn't work for hostnames with subdomains.
The code snippet below shows that localtunnel-server treats requests with subdomains as created instance which won't create clients for them, and it will continue return 404 to the client CLI.

server.on('request', (req, res) => {
    // without a hostname, we won't know who the request is for
    const hostname = req.headers.host;
    if (!hostname) {
        res.statusCode = 400;
        res.end('Host header is required');
        return;
    }

    // Doesn't handle subdomain
    const clientId = GetClientIdFromHostname(hostname);
    if (!clientId) {
        appCallback(req, res);
        return;
    }

    if (manager.hasClient(clientId)) {
        manager.handleRequest(clientId, req, res);
        return;
    }

    res.statusCode = 404;
    res.end('404');
});

function GetClientIdFromHostname(hostname) {
    // Also get the server's subdomain
    return tldjs.getSubdomain(hostname);
}

If this is the case, I hope localtunnel-server can add this features to fulfill its statement in README.md or at least delete this part from it.

You can set up DNS entries for your domain.tld and *.domain.tld (or sub.domain.tld and *.sub.domain.tld).
"Which just could not work and is waste of time for those who don't know this error."

Yes it still doesn't work for hostnames with subdomains. The code snippet below shows that localtunnel-server treats requests with subdomains as **created** instance which won't create clients for them, and it will continue return 404 to the client CLI. server.on('request', (req, res) => { // without a hostname, we won't know who the request is for const hostname = req.headers.host; if (!hostname) { res.statusCode = 400; res.end('Host header is required'); return; } // Doesn't handle subdomain const clientId = GetClientIdFromHostname(hostname); if (!clientId) { appCallback(req, res); return; } if (manager.hasClient(clientId)) { manager.handleRequest(clientId, req, res); return; } res.statusCode = 404; res.end('404'); }); function GetClientIdFromHostname(hostname) { // Also get the server's subdomain return tldjs.getSubdomain(hostname); } If this is the case, I hope localtunnel-server can add this features to fulfill its statement in `README.md` or at least delete this part from it. > You can set up DNS entries for your domain.tld and *.domain.tld (or sub.domain.tld and *.sub.domain.tld). "Which just could not work and is waste of time for those who don't know this error."
William-An commented 2018-03-03 03:21:35 +00:00 (Migrated from github.com)

@Spown The Nginx conf does not seem to cause this error but the code does.

@Spown The Nginx conf does not seem to cause this error but the code does.
Spown commented 2018-03-03 13:57:42 +00:00 (Migrated from github.com)

@William-An yeah, actually I forked both client and server, found the problem and almost fixed it, but then something else got broken. so I dropped it altogether and set it for root and custom port.

@William-An yeah, actually I forked both client and server, found the problem and almost fixed it, but then something else got broken. so I dropped it altogether and set it for root and custom port.
defunctzombie commented 2018-04-02 03:02:35 +00:00 (Migrated from github.com)

I have added the --domain option to handle situations where the localtunnel server is setup on a subdomain.

https://github.com/localtunnel/server/commit/86dce49dd1d40a64a2f121ff3aa271719417810f

Based on my reading of this issue this will resolve it. If not; please re-open with a more detailed description of your setup and what is not working.

I have added the _--domain_ option to handle situations where the localtunnel server is setup on a subdomain. https://github.com/localtunnel/server/commit/86dce49dd1d40a64a2f121ff3aa271719417810f Based on my reading of this issue this will resolve it. If not; please re-open with a more detailed description of your setup and what is not working.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: hoelee/server#69