Sub host options: ala whitecolor #82

Closed
gojisystems wants to merge 7 commits from master into master
4 changed files with 15 additions and 7 deletions
Showing only changes of commit 0eb59d42f9 - Show all commits
+5
View File
@@ -2,3 +2,8 @@ language: node_js
sudo: false sudo: false
node_js: node_js:
- "9.2" - "9.2"
addons:
hosts:
- host
- sub.host
- nested.sub.host
+4 -1
View File
@@ -12,17 +12,20 @@ const debug = Debug('localtunnel:server');
function GetClientIdFromHostname(hostname,opt) { function GetClientIdFromHostname(hostname,opt) {
let subdomain = tldjs.getSubdomain(hostname); let subdomain = tldjs.getSubdomain(hostname);
if (subdomain && opt.subHost) { if (subdomain && opt.subHost) {
const _subdomain = subdomain.replace(/\./g,''); const _subdomain = subdomain.replace(/\./g,'');
const subHosts = Array.isArray(opt.subHost) const subHosts = Array.isArray(opt.subHost)
? opt.subHost : [opt.subHost] ? opt.subHost : [opt.subHost]
const subHost = subHosts.reduce((found, sub) => { const subHost = subHosts.reduce((found, sub) => {
return found + (_subdomain.includes(sub) ? sub : ''); sub = sub.replace(/\./g,'');
return found + (_subdomain.includes(sub) ? sub : sub.includes(_subdomain) ? sub : '');
},'') },'')
subdomain = subHost.length > 0 subdomain = subHost.length > 0
? _subdomain.slice(0, -(subHost.length)) ? _subdomain.slice(0, -(subHost.length))
: subdomain : subdomain
} }
return subdomain; return subdomain;
} }
+3 -3
View File
@@ -70,14 +70,14 @@ test('should respond to request', function(done) {
}); });
test('set up localtunnel client (sub-host)', function (done) { test('set up localtunnel client (sub-host)', function (done) {
var opt = { var opt = {
host: 'http://nested.sub.localhost:' + lt_server_port, host: 'http://nested.sub.host:' + lt_server_port,
subdomain: 'txy-z' subdomain: 'txy-z'
}; };
localtunnel(test._fake_port, opt, function (err, tunnel) { localtunnel(test._fake_port, opt, function (err, tunnel) {
assert.ifError(err); assert.ifError(err);
var url = tunnel.url; var url = tunnel.url;
assert.ok(new RegExp('^http:\/\/.*nested.sub.localhost:' + lt_server_port + '$').test(url)); assert.ok(new RegExp('^http:\/\/.*nested.sub.host:' + lt_server_port + '$').test(url));
test._fake_url = url; test._fake_url = url;
done(err); done(err);
}); });
@@ -86,7 +86,7 @@ test('set up localtunnel client (sub-host)', function (done) {
test('should respond to request (sub-host)', function (done) { test('should respond to request (sub-host)', function (done) {
var hostname = url.parse(test._fake_url).hostname; var hostname = url.parse(test._fake_url).hostname;
var opt = { var opt = {
host: 'nested.sub.localhost', host: 'nested.sub.host',
port: lt_server_port, port: lt_server_port,
headers: { headers: {
host: hostname + '.tld' host: hostname + '.tld'
+3 -3
View File
@@ -75,13 +75,13 @@ test('websocket server request', function(done) {
}); });
test('set up localtunnel client (sub host)', function (done) { test('set up localtunnel client (sub host)', function (done) {
var opt = { var opt = {
host: 'http://sub.localhost:' + lt_server_port host: 'http://sub.host:' + lt_server_port
}; };
localtunnel(test._fake_port, opt, function (err, tunnel) { localtunnel(test._fake_port, opt, function (err, tunnel) {
assert.ifError(err); assert.ifError(err);
var url = tunnel.url; var url = tunnel.url;
assert.ok(new RegExp('^http:\/\/.*sub.localhost:' + lt_server_port + '$').test(url)); assert.ok(new RegExp('^http:\/\/.*sub.host:' + lt_server_port + '$').test(url));
test._fake_url = url; test._fake_url = url;
done(err); done(err);
}); });
@@ -89,7 +89,7 @@ test('set up localtunnel client (sub host)', function (done) {
test('websocket server request (sub-host)', function (done) { test('websocket server request (sub-host)', function (done) {
var hostname = url.parse(test._fake_url).hostname; var hostname = url.parse(test._fake_url).hostname;
var ws = new WebSocket('http://sub.localhost:' + lt_server_port, { var ws = new WebSocket('http://sub.host:' + lt_server_port, {
headers: { headers: {
host: hostname + '.tld' host: hostname + '.tld'
} }