diff --git a/server.js b/server.js index 7ba2106..495b5a9 100644 --- a/server.js +++ b/server.js @@ -81,7 +81,7 @@ module.exports = function(opt) { const req_id = parts[1]; // limit requested hostnames to 63 characters - if (! /^[a-z0-9]{4,63}$/.test(req_id)) { + if (! /^(?:[a-z0-9][a-z0-9\-]{4,63}[a-z0-9]|[a-z0-9]{4,63})$/.test(req_id)) { const msg = 'Invalid subdomain. Subdomains must be lowercase and between 4 and 63 alphanumeric characters.'; ctx.status = 403; ctx.body = { diff --git a/test/basic.js b/test/basic.js index f1c829d..786e931 100644 --- a/test/basic.js +++ b/test/basic.js @@ -118,6 +118,21 @@ test('request specific domain', function(done) { }); }); +test('request domain with dash', function(done) { + var opt = { + host: 'http://localhost:' + lt_server_port, + subdomain: 'abcd-1234' + }; + + localtunnel(test._fake_port, opt, function(err, tunnel) { + assert.ifError(err); + var url = tunnel.url; + assert.ok(new RegExp('^http:\/\/.*localhost:' + lt_server_port + '$').test(url)); + test._fake_url = url; + done(err); + }); +}); + test('request domain that is too long', function(done) { var opt = { host: 'http://localhost:' + lt_server_port,