Sub host options: ala whitecolor #82
@@ -12,25 +12,23 @@ const debug = Debug('localtunnel:server');
|
|||||||
|
|
||||||
function GetClientIdFromHostname(hostname,opt) {
|
function GetClientIdFromHostname(hostname,opt) {
|
||||||
let subdomain = tldjs.getSubdomain(hostname);
|
let subdomain = tldjs.getSubdomain(hostname);
|
||||||
console.log(opt,'option');
|
|
||||||
console.log(hostname,'hostname');
|
|
||||||
console.log(subdomain,'subdomain');
|
|
||||||
if (subdomain && opt.subHost) {
|
if (subdomain && opt.subHost) {
|
||||||
|
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
|
sub = sub.replace(/\./g,'');
|
||||||
|| (subdomain.slice(-sub.length) == sub ? sub : '')
|
return found + (_subdomain.includes(sub) ? sub : '');
|
||||||
},'')
|
},'')
|
||||||
subdomain = subHost
|
subdomain = subHost.length > 0
|
||||||
? subdomain.slice(0, -(subHost.length + 1))
|
? _subdomain.slice(0, -(subHost.length))
|
||||||
: subdomain
|
: subdomain
|
||||||
}
|
}
|
||||||
return subdomain;
|
return subdomain;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function(opt) {
|
module.exports = function(opt) {
|
||||||
console.log(opt);
|
|
||||||
opt = opt || {};
|
opt = opt || {};
|
||||||
|
|
||||||
const manager = new ClientManager(opt);
|
const manager = new ClientManager(opt);
|
||||||
@@ -126,7 +124,7 @@ module.exports = function(opt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const clientId = GetClientIdFromHostname(hostname,opt);
|
const clientId = GetClientIdFromHostname(hostname,opt);
|
||||||
console.log(clientId,'clientId response');
|
|
||||||
if (!clientId) {
|
if (!clientId) {
|
||||||
appCallback(req, res);
|
appCallback(req, res);
|
||||||
return;
|
return;
|
||||||
@@ -144,13 +142,13 @@ module.exports = function(opt) {
|
|||||||
server.on('upgrade', (req, socket, head) => {
|
server.on('upgrade', (req, socket, head) => {
|
||||||
const hostname = req.headers.host;
|
const hostname = req.headers.host;
|
||||||
if (!hostname) {
|
if (!hostname) {
|
||||||
sock.destroy();
|
socket.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientId = GetClientIdFromHostname(hostname,opt);
|
const clientId = GetClientIdFromHostname(hostname,opt);
|
||||||
if (!clientId) {
|
if (!clientId) {
|
||||||
sock.destroy();
|
socket.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -5,7 +5,7 @@ var localtunnel = require('localtunnel');
|
|||||||
|
|
||||||
var localtunnel_server = require('../server')({
|
var localtunnel_server = require('../server')({
|
||||||
max_tcp_sockets: 2,
|
max_tcp_sockets: 2,
|
||||||
subHost: ['nested.sub','nested','sub']
|
subHost: ['nested','sub']
|
||||||
});
|
});
|
||||||
|
|
||||||
var lt_server_port
|
var lt_server_port
|
||||||
@@ -75,7 +75,6 @@ test('set up localtunnel client (sub-host)', function (done) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
localtunnel(test._fake_port, opt, function (err, tunnel) {
|
localtunnel(test._fake_port, opt, function (err, tunnel) {
|
||||||
console.log(url);
|
|
||||||
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.localhost:' + lt_server_port + '$').test(url));
|
||||||
|
|||||||
Reference in New Issue
Block a user