mirror of
https://github.com/bitinflow/server.git
synced 2026-03-13 13:35:53 +00:00
fix bad matching against subdomains
Match for valid subdomains versus anything that comes before a period. fixes #7
This commit is contained in:
@@ -26,7 +26,8 @@
|
|||||||
"bouncy": "3.2.1",
|
"bouncy": "3.2.1",
|
||||||
"superstack": "0.0.4",
|
"superstack": "0.0.4",
|
||||||
"stylish": "0.4.1",
|
"stylish": "0.4.1",
|
||||||
"makeover": "0.0.1"
|
"makeover": "0.0.1",
|
||||||
|
"tldjs": "1.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": "1.18.2",
|
"mocha": "1.18.2",
|
||||||
|
|||||||
11
server.js
11
server.js
@@ -8,6 +8,7 @@ var makeover = require('makeover');
|
|||||||
var makeup = require('makeup');
|
var makeup = require('makeup');
|
||||||
var engine = require('engine.io');
|
var engine = require('engine.io');
|
||||||
var browserkthx = require('browserkthx');
|
var browserkthx = require('browserkthx');
|
||||||
|
var tldjs = require('tldjs');
|
||||||
var debug = require('debug')('localtunnel-server');
|
var debug = require('debug')('localtunnel-server');
|
||||||
|
|
||||||
var Proxy = require('./proxy');
|
var Proxy = require('./proxy');
|
||||||
@@ -32,16 +33,12 @@ function maybe_bounce(req, res, bounce) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract the subdomain, which is the client id
|
var subdomain = tldjs.getSubdomain(hostname);
|
||||||
var match = hostname.match(/^([a-z0-9]+)[.].*/);
|
if (!subdomain) {
|
||||||
|
|
||||||
// not for a specific client
|
|
||||||
// pass on to regular server
|
|
||||||
if (!match) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var client_id = match[1];
|
var client_id = subdomain;
|
||||||
var client = clients[client_id];
|
var client = clients[client_id];
|
||||||
|
|
||||||
// no such subdomain
|
// no such subdomain
|
||||||
|
|||||||
@@ -15,6 +15,33 @@ test('setup localtunnel server', function(done) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('landing page', function(done) {
|
||||||
|
var opt = {
|
||||||
|
host: 'localhost',
|
||||||
|
port: lt_server_port,
|
||||||
|
headers: {
|
||||||
|
host: 'example.com'
|
||||||
|
},
|
||||||
|
path: '/'
|
||||||
|
}
|
||||||
|
|
||||||
|
var req = http.request(opt, function(res) {
|
||||||
|
res.setEncoding('utf8');
|
||||||
|
var body = '';
|
||||||
|
|
||||||
|
res.on('data', function(chunk) {
|
||||||
|
body += chunk;
|
||||||
|
});
|
||||||
|
|
||||||
|
res.on('end', function() {
|
||||||
|
assert(body.indexOf('<h2>expose yourself to the world</h2>') > 0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
req.end();
|
||||||
|
});
|
||||||
|
|
||||||
test('setup local http server', function(done) {
|
test('setup local http server', function(done) {
|
||||||
var server = http.createServer();
|
var server = http.createServer();
|
||||||
server.on('request', function(req, res) {
|
server.on('request', function(req, res) {
|
||||||
@@ -52,7 +79,7 @@ test('query localtunnel server w/ ident', function(done) {
|
|||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: lt_server_port,
|
port: lt_server_port,
|
||||||
headers: {
|
headers: {
|
||||||
host: hostname
|
host: hostname + '.tld'
|
||||||
},
|
},
|
||||||
path: '/'
|
path: '/'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ test('query localtunnel server w/ ident', function(done) {
|
|||||||
port: lt_server_port,
|
port: lt_server_port,
|
||||||
agent: false,
|
agent: false,
|
||||||
headers: {
|
headers: {
|
||||||
host: hostname
|
host: hostname + '.tld'
|
||||||
},
|
},
|
||||||
path: '/'
|
path: '/'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user