/
vhost.test.js
61 lines (48 loc) · 1.47 KB
/
vhost.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Module dependencies.
*/
var connect = require('../')
, assert = require('assert')
, should = require('should')
, http = require('http');
module.exports = {
'test with host': function(){
var a = connect.createServer(function(req, res){
res.end('from foo');
});
var b = connect.createServer(function(req, res){
res.end('from bar');
});
var app = connect.createServer(
connect.vhost('foo.com', a)
, connect.vhost('bar.com', b)
);
assert.response(app,
{ url: '/', headers: { Host: 'foo.com' }},
{ body: 'from foo' });
assert.response(app,
{ url: '/', headers: { Host: 'bar.com' }},
{ body: 'from bar' });
assert.response(app,
{ url: '/', headers: { Host: 'other.com' }},
{ body: 'Cannot GET /', status: 404 });
},
'test with wildcard': function(){
var server = connect.createServer(function(req, res){
res.end('from ' + req.subdomains.join(', '));
});
var app = connect.createServer(
connect.vhost('*.foo.com', server)
, connect.vhost('foo.com', server)
);
assert.response(app,
{ url: '/', headers: { Host: 'foo.com' }},
{ body: 'from foo' });
assert.response(app,
{ url: '/', headers: { Host: 'tj.foo.com' }},
{ body: 'from tj, foo' });
assert.response(app,
{ url: '/', headers: { Host: 'holowaychuk.tj.foo.com' }},
{ body: 'from holowaychuk, tj, foo' });
}
};