mirror of
https://github.com/bitinflow/server.git
synced 2026-03-13 13:35:53 +00:00
Generate human readable IDs for client URLs (#77)
Based on @FranzSkuffka's suggested enhancement in PR 207 on localtunnel/localtunnel (https://github.com/localtunnel/localtunnel/pull/207), this PR uses the "human-readable-ids" package to generate IDs of the form "adjective-noun-number". These IDs are easier to remember and arguably more useful in testing since they can be retyped without copying and pasting. Some sample IDs generated by this package are: * heavy-puma-90 * grump-walrus-64 * purple-starfish-58 * nasty-seahorse-9
This commit is contained in:
committed by
Roman Shtylman
parent
d7852a3dd1
commit
b1c296a409
@@ -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.
|
||||
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
10
yarn.lock
10
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"
|
||||
|
||||
Reference in New Issue
Block a user