diff --git a/README.md b/README.md index c557c94..8918376 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ You can now use your domain with the `--host` flag for the `lt` client. lt --host http://sub.example.tld:1234 --port 9000 ``` -You will be assigned a URL similar to `qdci.sub.example.com:1234`. +You will be assigned a URL similar to `heavy-puma-9.sub.example.com:1234`. If your server is acting as a reverse proxy (i.e. nginx) and is able to listen on port 80, then you do not need the `:1234` part of the hostname for the `lt` client. diff --git a/lib/ClientManager.js b/lib/ClientManager.js index 2d798a1..a4199f9 100644 --- a/lib/ClientManager.js +++ b/lib/ClientManager.js @@ -4,8 +4,8 @@ import Proxy from './Proxy'; import on_finished from 'on-finished'; import http from 'http'; import pump from 'pump'; +import { hri } from "human-readable-ids"; -import rand_id from './rand_id'; import BindingAgent from './BindingAgent'; const NoOp = () => {}; @@ -36,7 +36,7 @@ class ClientManager { // can't ask for id already is use if (clients[id]) { - id = rand_id(); + id = hri.random(); } const popt = { diff --git a/lib/rand_id.js b/lib/rand_id.js deleted file mode 100644 index f76f6d8..0000000 --- a/lib/rand_id.js +++ /dev/null @@ -1,13 +0,0 @@ -// all url safe -// can't use uppercase because hostnames are lowercased -const chars = 'abcdefghijklmnopqrstuvwxyz'; - -export default function rand_id() { - let randomstring = ''; - for (var i=0; i<10; ++i) { - const rnum = Math.floor(Math.random() * chars.length); - randomstring += chars[rnum]; - } - - return randomstring; -} diff --git a/package.json b/package.json index 0ba80a0..0908e04 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "bluebird": "3.5.1", "book": "1.3.3", "debug": "3.1.0", + "human-readable-ids": "1.0.3", "koa": "2.4.1", "localenv": "0.2.2", "on-finished": "2.3.0", diff --git a/server.js b/server.js index 5dd08b0..7ba2106 100644 --- a/server.js +++ b/server.js @@ -4,9 +4,9 @@ import tldjs from 'tldjs'; import Debug from 'debug'; import http from 'http'; import Promise from 'bluebird'; +import { hri } from 'human-readable-ids'; import ClientManager from './lib/ClientManager'; -import rand_id from './lib/rand_id'; const debug = Debug('localtunnel:server'); @@ -51,7 +51,7 @@ module.exports = function(opt) { const isNewClientRequest = ctx.query['new'] !== undefined; if (isNewClientRequest) { - const req_id = rand_id(); + const req_id = hri.random(); debug('making new client with id %s', req_id); const info = await manager.newClient(req_id); diff --git a/yarn.lock b/yarn.lock index 265f847..156462e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -615,6 +615,12 @@ http-signature@~0.11.0: assert-plus "^0.1.5" ctype "0.5.3" +human-readable-ids@1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/human-readable-ids/-/human-readable-ids-1.0.3.tgz#c8c6c6e95085ccb668087b7dd767834e26ca26d4" + dependencies: + knuth-shuffle "^1.0.0" + indent-string@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-2.1.0.tgz#8e2d48348742121b4a8218b7a137e9a52049dc80" @@ -733,6 +739,10 @@ keygrip@~1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/keygrip/-/keygrip-1.0.2.tgz#ad3297c557069dea8bcfe7a4fa491b75c5ddeb91" +knuth-shuffle@^1.0.0: + version "1.0.8" + resolved "https://registry.yarnpkg.com/knuth-shuffle/-/knuth-shuffle-1.0.8.tgz#929a467b0efd8d297bdcf318ca988a9f1037f80d" + koa-compose@^3.0.0: version "3.2.1" resolved "https://registry.yarnpkg.com/koa-compose/-/koa-compose-3.2.1.tgz#a85ccb40b7d986d8e5a345b3a1ace8eabcf54de7"