120 lines
4.7 KiB
JavaScript
120 lines
4.7 KiB
JavaScript
|
const args = require('minimist')( process.argv.splice(2) )
|
||
|
require('colors')
|
||
|
require('log')
|
||
|
const domains = require('../src/domains.js')('domains-exemple')
|
||
|
const bouncy = require('./bouncy-mock.js')
|
||
|
|
||
|
require('./proxy-testcases.js').map( test )
|
||
|
|
||
|
|
||
|
|
||
|
function test( host )
|
||
|
{
|
||
|
let domain, res, debug = [],
|
||
|
[ ,,subDomain, mainDomain, tld ] = /^((.*)\.)*(.*?)\.(.*)$/.exec( /*req.headers.*/host )
|
||
|
// console.log( /^((.*)\.)*(.*?)\.(.*)$/.exec( /*req.headers.*/host ) )
|
||
|
// console.log( 'subdomain: %s\ndomain: %s\ntld: %s', subDomain, domain, tld )
|
||
|
|
||
|
for( domain of domains )
|
||
|
{
|
||
|
if( res = domain.test.exec(host) )
|
||
|
{
|
||
|
debug.push([
|
||
|
domain,
|
||
|
domain.test, res,
|
||
|
domain.resolve( subDomain, mainDomain, tld, res )
|
||
|
])
|
||
|
}
|
||
|
}/*
|
||
|
let debug = domains.map( arr=> {
|
||
|
var res//, reg = new RegExp('^'+arr[0].replace(/\* /g, '(.*?)')+'$')
|
||
|
//, fun = ( subDomain, domain, tld, match )=> eval('`'+arr[1]+'`')
|
||
|
if( res = arr.test.exec(host) )
|
||
|
{
|
||
|
return [ arr[0], arr.test, res, arr[1], arr.resolve( subDomain, domain, tld, res ) ]
|
||
|
}
|
||
|
})*/
|
||
|
|
||
|
debug.length ?
|
||
|
log`===============================================
|
||
|
${'Testing'.grey}s "${host.cyan}s"
|
||
|
-----------------
|
||
|
Split: ${(subDomain+'').bgWhite.red}s.${mainDomain.bgWhite.blue}s.${tld.grey}s
|
||
|
Match: ${debug[0][0][0].magenta}s\t${debug[0][0][1].yellow}s
|
||
|
>>> 127.0.0.1:${debug[0][3].green}s
|
||
|
----------------
|
||
|
${debug}o
|
||
|
`
|
||
|
: log`===============================================
|
||
|
${'Testing'.grey}s "${host.cyan}s"
|
||
|
-----------------
|
||
|
Split: ${(subDomain+'').bgWhite.red}s.${mainDomain.bgWhite.blue}s.${tld.grey}s
|
||
|
Match: ${'none'.red}s
|
||
|
----------------
|
||
|
${debug}o
|
||
|
`
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/*
|
||
|
require`bouncy`( (req,res,hop) => {
|
||
|
req.headers.host in config && hop( config[req.headers.host] )
|
||
|
req.headers.host in config && hop( config[req.headers.host] )
|
||
|
}).listen( 80 )
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
require`bouncy`( (req,res,hop) => {
|
||
|
let [ subDomain, domain, tld ] = /^(.*?)\.(.*?)\.(.*)$/.exec( req.headers.host );
|
||
|
//||||___________________________________|_______|______|_______||||____________|______||_|___________________________________
|
||
|
case 'nuitdebook.io' : bounce( 31316 ); break; // 31/03/16
|
||
|
case 'nuitdebook.city' : bounce( 31316, { path: '/tag/' + subDomain } ); break;
|
||
|
default : res.statusCode = 404; res.end( 'no such host: ' + req.headers.host ); break;
|
||
|
|
||
|
}).listen( 80 )
|
||
|
|
||
|
*/
|
||
|
|
||
|
|
||
|
/*
|
||
|
require('bouncy')(function (req, res, bounce) {
|
||
|
//console.log(req.headers, req.headers.host);
|
||
|
var host = req.headers.host.split('.')
|
||
|
, tld = host.pop()
|
||
|
, domain = host.pop() + '.' + tld
|
||
|
, subDomain = host.join('.')
|
||
|
;/^(.*?)\.(.*?)\.(.*)$/.exec( req.headers.host )9169 9149 14
|
||
|
//res.end("d:"+domain+" | t:"+tld+" s:"+subDomain);
|
||
|
switch( domain ) {
|
||
|
|
||
|
// case'(subDomain).(domain).(tld)' : bounce( port ); break; // Memo ...
|
||
|
// ||||_____________________|_______|______|_______||||____________|_______||_|__________________________
|
||
|
case 'devingfx.com' : bounce( 8080 ); break;
|
||
|
case 'www.devingfx.com' : bounce( 8080 ); break;
|
||
|
case 'money.devingfx.com' : bounce( 9888 ); break;
|
||
|
case 'ipfs.devingfx.com' : bounce( 9169 ); break; // IPNS > 9 16 6 19
|
||
|
case 'ipns.devingfx.com' : bounce( 9149 ); break; // IPFS > 9 16 14 19
|
||
|
case 'ipdb.devingfx.com' : bounce( 9149 ); break; // IPDB >
|
||
|
|
||
|
// case 'nicedebout.devingfx.com' : bounce( 3333 ); break;
|
||
|
case 'nuitdeboutnice.fr' : bounce( 6776 ); break;
|
||
|
case 'nuideboutnice.fr' : bounce( 6776 ); break;
|
||
|
// case 'www.nuitdeboutnice.fr' : bounce( 3333 ); break;
|
||
|
// case 'www.nuideboutnice.fr' : bounce( 3333 ); break;
|
||
|
// case 'www.nuitdeboutnice.fr' : bounce( 3333 ); break;
|
||
|
// case 'www.nuitdeboutnice.fr' : bounce( 3103 ); break;
|
||
|
// case 'nuitdeboutnice.fr' : bounce( 3103 ); break;
|
||
|
case 'nuitdebook.io' : bounce( 31316 ); break; // 31/03/16
|
||
|
|
||
|
case 'nuitdebook.city' : bounce( 31316, { path: '/tag/' + subDomain } ); break;
|
||
|
|
||
|
default: res.statusCode = 404; res.end( 'no such host: ' + req.headers.host ); break;
|
||
|
}
|
||
|
|
||
|
}).listen( 80 );
|
||
|
*/
|