@@ -4,25 +4,25 @@ var http = require('http')
44var request = require ( 'supertest' )
55var vhost = require ( '..' )
66
7- describe ( 'vhost(hostname, server)' , function ( ) {
8- it ( 'should route by Host' , function ( done ) {
7+ describe ( 'vhost(hostname, server)' , function ( ) {
8+ it ( 'should route by Host' , function ( done ) {
99 var vhosts = [ ]
1010
1111 vhosts . push ( vhost ( 'tobi.com' , tobi ) )
1212 vhosts . push ( vhost ( 'loki.com' , loki ) )
1313
1414 var app = createServer ( vhosts )
1515
16- function tobi ( req , res ) { res . end ( 'tobi' ) }
17- function loki ( req , res ) { res . end ( 'loki' ) }
16+ function tobi ( req , res ) { res . end ( 'tobi' ) }
17+ function loki ( req , res ) { res . end ( 'loki' ) }
1818
1919 request ( app )
2020 . get ( '/' )
2121 . set ( 'Host' , 'tobi.com' )
2222 . expect ( 200 , 'tobi' , done )
2323 } )
2424
25- it ( 'should ignore port in Host' , function ( done ) {
25+ it ( 'should ignore port in Host' , function ( done ) {
2626 var app = createServer ( 'tobi.com' , function ( req , res ) {
2727 res . end ( 'tobi' )
2828 } )
@@ -33,7 +33,7 @@ describe('vhost(hostname, server)', function(){
3333 . expect ( 200 , 'tobi' , done )
3434 } )
3535
36- it ( 'should support IPv6 literal in Host' , function ( done ) {
36+ it ( 'should support IPv6 literal in Host' , function ( done ) {
3737 var app = createServer ( '[::1]' , function ( req , res ) {
3838 res . end ( 'loopback' )
3939 } )
@@ -44,73 +44,73 @@ describe('vhost(hostname, server)', function(){
4444 . expect ( 200 , 'loopback' , done )
4545 } )
4646
47- it ( 'should 404 unless matched' , function ( done ) {
47+ it ( 'should 404 unless matched' , function ( done ) {
4848 var vhosts = [ ]
4949
5050 vhosts . push ( vhost ( 'tobi.com' , tobi ) )
5151 vhosts . push ( vhost ( 'loki.com' , loki ) )
5252
5353 var app = createServer ( vhosts )
5454
55- function tobi ( req , res ) { res . end ( 'tobi' ) }
56- function loki ( req , res ) { res . end ( 'loki' ) }
55+ function tobi ( req , res ) { res . end ( 'tobi' ) }
56+ function loki ( req , res ) { res . end ( 'loki' ) }
5757
5858 request ( app . listen ( ) )
5959 . get ( '/' )
6060 . set ( 'Host' , 'ferrets.com' )
6161 . expect ( 404 , done )
6262 } )
6363
64- it ( 'should 404 without Host header' , function ( done ) {
64+ it ( 'should 404 without Host header' , function ( done ) {
6565 var vhosts = [ ]
6666
6767 vhosts . push ( vhost ( 'tobi.com' , tobi ) )
6868 vhosts . push ( vhost ( 'loki.com' , loki ) )
6969
7070 var app = createServer ( vhosts )
7171
72- function tobi ( req , res ) { res . end ( 'tobi' ) }
73- function loki ( req , res ) { res . end ( 'loki' ) }
72+ function tobi ( req , res ) { res . end ( 'tobi' ) }
73+ function loki ( req , res ) { res . end ( 'loki' ) }
7474
7575 request ( app . listen ( ) )
7676 . get ( '/' )
7777 . unset ( 'Host' )
7878 . expect ( 404 , done )
7979 } )
8080
81- describe ( 'arguments' , function ( ) {
82- describe ( 'hostname' , function ( ) {
83- it ( 'should be required' , function ( ) {
81+ describe ( 'arguments' , function ( ) {
82+ describe ( 'hostname' , function ( ) {
83+ it ( 'should be required' , function ( ) {
8484 assert . throws ( vhost . bind ( ) , / h o s t n a m e .* r e q u i r e d / )
8585 } )
8686
87- it ( 'should accept string' , function ( ) {
88- assert . doesNotThrow ( vhost . bind ( null , 'loki.com' , function ( ) { } ) )
87+ it ( 'should accept string' , function ( ) {
88+ assert . doesNotThrow ( vhost . bind ( null , 'loki.com' , function ( ) { } ) )
8989 } )
9090
91- it ( 'should accept RegExp' , function ( ) {
92- assert . doesNotThrow ( vhost . bind ( null , / l o k i \. c o m / , function ( ) { } ) )
91+ it ( 'should accept RegExp' , function ( ) {
92+ assert . doesNotThrow ( vhost . bind ( null , / l o k i \. c o m / , function ( ) { } ) )
9393 } )
9494 } )
9595
96- describe ( 'handle' , function ( ) {
97- it ( 'should be required' , function ( ) {
96+ describe ( 'handle' , function ( ) {
97+ it ( 'should be required' , function ( ) {
9898 assert . throws ( vhost . bind ( null , 'loki.com' ) , / h a n d l e .* r e q u i r e d / )
9999 } )
100100
101- it ( 'should accept function' , function ( ) {
102- assert . doesNotThrow ( vhost . bind ( null , 'loki.com' , function ( ) { } ) )
101+ it ( 'should accept function' , function ( ) {
102+ assert . doesNotThrow ( vhost . bind ( null , 'loki.com' , function ( ) { } ) )
103103 } )
104104
105- it ( 'should reject plain object' , function ( ) {
105+ it ( 'should reject plain object' , function ( ) {
106106 assert . throws ( vhost . bind ( null , 'loki.com' , { } ) , / h a n d l e .* f u n c t i o n / )
107107 } )
108108 } )
109109 } )
110110
111- describe ( 'with string hostname' , function ( ) {
112- it ( 'should support wildcards' , function ( done ) {
113- var app = createServer ( '*.ferrets.com' , function ( req , res ) {
111+ describe ( 'with string hostname' , function ( ) {
112+ it ( 'should support wildcards' , function ( done ) {
113+ var app = createServer ( '*.ferrets.com' , function ( req , res ) {
114114 res . end ( 'wildcard!' )
115115 } )
116116
@@ -120,8 +120,8 @@ describe('vhost(hostname, server)', function(){
120120 . expect ( 200 , 'wildcard!' , done )
121121 } )
122122
123- it ( 'should restrict wildcards to single part' , function ( done ) {
124- var app = createServer ( '*.ferrets.com' , function ( req , res ) {
123+ it ( 'should restrict wildcards to single part' , function ( done ) {
124+ var app = createServer ( '*.ferrets.com' , function ( req , res ) {
125125 res . end ( 'wildcard!' )
126126 } )
127127
@@ -131,8 +131,8 @@ describe('vhost(hostname, server)', function(){
131131 . expect ( 404 , done )
132132 } )
133133
134- it ( 'should treat dot as a dot' , function ( done ) {
135- var app = createServer ( 'a.b.com' , function ( req , res ) {
134+ it ( 'should treat dot as a dot' , function ( done ) {
135+ var app = createServer ( 'a.b.com' , function ( req , res ) {
136136 res . end ( 'tobi' )
137137 } )
138138
@@ -142,8 +142,8 @@ describe('vhost(hostname, server)', function(){
142142 . expect ( 404 , done )
143143 } )
144144
145- it ( 'should match entire string' , function ( done ) {
146- var app = createServer ( '.com' , function ( req , res ) {
145+ it ( 'should match entire string' , function ( done ) {
146+ var app = createServer ( '.com' , function ( req , res ) {
147147 res . end ( 'commercial' )
148148 } )
149149
@@ -153,10 +153,10 @@ describe('vhost(hostname, server)', function(){
153153 . expect ( 404 , done )
154154 } )
155155
156- it ( 'should populate req.vhost' , function ( done ) {
157- var app = createServer ( 'user-*.*.com' , function ( req , res ) {
156+ it ( 'should populate req.vhost' , function ( done ) {
157+ var app = createServer ( 'user-*.*.com' , function ( req , res ) {
158158 var keys = Object . keys ( req . vhost ) . sort ( )
159- var arr = keys . map ( function ( k ) { return [ k , req . vhost [ k ] ] } )
159+ var arr = keys . map ( function ( k ) { return [ k , req . vhost [ k ] ] } )
160160 res . end ( JSON . stringify ( arr ) )
161161 } )
162162
@@ -167,9 +167,9 @@ describe('vhost(hostname, server)', function(){
167167 } )
168168 } )
169169
170- describe ( 'with RegExp hostname' , function ( ) {
171- it ( 'should match using RegExp' , function ( done ) {
172- var app = createServer ( / [ t l ] o [ b k ] i \. c o m / , function ( req , res ) {
170+ describe ( 'with RegExp hostname' , function ( ) {
171+ it ( 'should match using RegExp' , function ( done ) {
172+ var app = createServer ( / [ t l ] o [ b k ] i \. c o m / , function ( req , res ) {
173173 res . end ( 'tobi' )
174174 } )
175175
@@ -179,27 +179,27 @@ describe('vhost(hostname, server)', function(){
179179 . expect ( 200 , 'tobi' , done )
180180 } )
181181
182- it ( 'should match entire hostname' , function ( done ) {
182+ it ( 'should match entire hostname' , function ( done ) {
183183 var vhosts = [ ]
184184
185185 vhosts . push ( vhost ( / \. t o b i $ / , tobi ) )
186186 vhosts . push ( vhost ( / ^ l o k i \. / , loki ) )
187187
188188 var app = createServer ( vhosts )
189189
190- function tobi ( req , res ) { res . end ( 'tobi' ) }
191- function loki ( req , res ) { res . end ( 'loki' ) }
190+ function tobi ( req , res ) { res . end ( 'tobi' ) }
191+ function loki ( req , res ) { res . end ( 'loki' ) }
192192
193193 request ( app )
194194 . get ( '/' )
195195 . set ( 'Host' , 'loki.tobi.com' )
196196 . expect ( 404 , done )
197197 } )
198198
199- it ( 'should populate req.vhost' , function ( done ) {
200- var app = createServer ( / u s e r - ( b o b | j o e ) \. ( [ ^ \. ] + ) \. c o m / , function ( req , res ) {
199+ it ( 'should populate req.vhost' , function ( done ) {
200+ var app = createServer ( / u s e r - ( b o b | j o e ) \. ( [ ^ \. ] + ) \. c o m / , function ( req , res ) {
201201 var keys = Object . keys ( req . vhost ) . sort ( )
202- var arr = keys . map ( function ( k ) { return [ k , req . vhost [ k ] ] } )
202+ var arr = keys . map ( function ( k ) { return [ k , req . vhost [ k ] ] } )
203203 res . end ( JSON . stringify ( arr ) )
204204 } )
205205
@@ -211,15 +211,15 @@ describe('vhost(hostname, server)', function(){
211211 } )
212212} )
213213
214- function createServer ( hostname , server ) {
214+ function createServer ( hostname , server ) {
215215 var vhosts = ! Array . isArray ( hostname )
216216 ? [ vhost ( hostname , server ) ]
217217 : hostname
218218
219- return http . createServer ( function onRequest ( req , res ) {
219+ return http . createServer ( function onRequest ( req , res ) {
220220 var index = 0
221221
222- function next ( err ) {
222+ function next ( err ) {
223223 var vhost = vhosts [ index ++ ]
224224
225225 if ( ! vhost || err ) {
0 commit comments