Sub host options: ala whitecolor #82
@@ -12,25 +12,23 @@ const debug = Debug('localtunnel:server');
|
||||
|
||||
function GetClientIdFromHostname(hostname,opt) {
|
||||
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)
|
||||
? opt.subHost : [opt.subHost]
|
||||
const subHost = subHosts.reduce((found, sub) => {
|
||||
return found
|
||||
|| (subdomain.slice(-sub.length) == sub ? sub : '')
|
||||
}, '')
|
||||
subdomain = subHost
|
||||
? subdomain.slice(0, -(subHost.length + 1))
|
||||
const subHost = subHosts.reduce((found, sub) => {
|
||||
sub = sub.replace(/\./g,'');
|
||||
return found + (_subdomain.includes(sub) ? sub : '');
|
||||
},'')
|
||||
subdomain = subHost.length > 0
|
||||
? _subdomain.slice(0, -(subHost.length))
|
||||
: subdomain
|
||||
}
|
||||
return subdomain;
|
||||
}
|
||||
|
||||
module.exports = function(opt) {
|
||||
console.log(opt);
|
||||
|
||||
opt = opt || {};
|
||||
|
||||
const manager = new ClientManager(opt);
|
||||
@@ -124,9 +122,9 @@ module.exports = function(opt) {
|
||||
res.end('Host header is required');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const clientId = GetClientIdFromHostname(hostname,opt);
|
||||
console.log(clientId,'clientId response');
|
||||
|
||||
if (!clientId) {
|
||||
appCallback(req, res);
|
||||
return;
|
||||
@@ -144,13 +142,13 @@ module.exports = function(opt) {
|
||||
server.on('upgrade', (req, socket, head) => {
|
||||
const hostname = req.headers.host;
|
||||
if (!hostname) {
|
||||
sock.destroy();
|
||||
socket.destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
const clientId = GetClientIdFromHostname(hostname,opt);
|
||||
if (!clientId) {
|
||||
sock.destroy();
|
||||
socket.destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -5,7 +5,7 @@ var localtunnel = require('localtunnel');
|
||||
|
||||
var localtunnel_server = require('../server')({
|
||||
max_tcp_sockets: 2,
|
||||
subHost: ['nested.sub','nested','sub']
|
||||
subHost: ['nested','sub']
|
||||
});
|
||||
|
||||
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) {
|
||||
console.log(url);
|
||||
assert.ifError(err);
|
||||
var url = tunnel.url;
|
||||
assert.ok(new RegExp('^http:\/\/.*nested.sub.localhost:' + lt_server_port + '$').test(url));
|
||||
|
||||
Reference in New Issue
Block a user