@@ -100,7 +100,8 @@ describe('static resource plugin', function () {
100100 }
101101
102102 if ( testDefault ) {
103- opts . defaultFile = testFileName ;
103+ p = '/' + testDir + '/' ;
104+ opts . default = testFileName ;
104105 routeName += ' with default' ;
105106 }
106107 var re = regex ||
@@ -121,7 +122,61 @@ describe('static resource plugin', function () {
121122 } ) ;
122123 } ) ;
123124 } ) ;
125+ }
126+
127+ function testNoAppendPath ( done , testDefault , tmpDir , regex , staticFile ) {
128+ var staticContent = '{"content": "abcdefg"}' ;
129+ var staticObj = JSON . parse ( staticContent ) ;
130+ var testDir = 'public' ;
131+ var testFileName = 'index.json' ;
132+ var routeName = 'GET wildcard' ;
133+ var tmpPath = path . join ( __dirname , '../' , tmpDir ) ;
134+
135+ mkdirp ( tmpPath , function ( err ) {
136+ assert . ifError ( err ) ;
137+ DIRS_TO_DELETE . push ( tmpPath ) ;
138+ var folderPath = path . join ( tmpPath , testDir ) ;
139+
140+ mkdirp ( folderPath , function ( err2 ) {
141+ assert . ifError ( err2 ) ;
142+
143+ DIRS_TO_DELETE . push ( folderPath ) ;
144+ var file = path . join ( folderPath , testFileName ) ;
145+
146+ fs . writeFile ( file , staticContent , function ( err3 ) {
147+ assert . ifError ( err3 ) ;
148+ FILES_TO_DELETE . push ( file ) ;
149+ var p = '/' + testDir + '/' + testFileName ;
150+ var opts = { directory : folderPath } ;
151+ opts . appendRequestPath = false ;
152+
153+ if ( staticFile ) {
154+ opts . file = testFileName ;
155+ }
124156
157+ if ( testDefault ) {
158+ p = '/' + testDir + '/' ;
159+ opts . default = testFileName ;
160+ routeName += ' with default' ;
161+ }
162+ var re = regex ||
163+ new RegExp ( '/' + testDir + '/?.*' ) ;
164+
165+ SERVER . get ( {
166+ path : re ,
167+ name : routeName
168+ } , plugins . serveStatic ( opts ) ) ;
169+
170+ CLIENT . get ( p , function ( err4 , req , res , obj ) {
171+ assert . ifError ( err4 ) ;
172+ assert . equal ( res . headers [ 'cache-control' ] ,
173+ 'public, max-age=3600' ) ;
174+ assert . deepEqual ( obj , staticObj ) ;
175+ done ( ) ;
176+ } ) ;
177+ } ) ;
178+ } ) ;
179+ } ) ;
125180 }
126181
127182 it ( 'static serves static files' , function ( done ) {
@@ -162,4 +217,18 @@ describe('static resource plugin', function () {
162217 serveStaticTest ( done , false , '.tmp' , null , true ) ;
163218 } ) ;
164219
220+ it ( 'static serves static file with appendRequestPath = false' ,
221+ function ( done ) {
222+ testNoAppendPath ( done , false , '.tmp' ) ;
223+ } ) ;
224+
225+ it ( 'static serves default file with appendRequestPath = false' ,
226+ function ( done ) {
227+ testNoAppendPath ( done , true , '.tmp' ) ;
228+ } ) ;
229+
230+ it ( 'restify serve a specific static file with appendRequestPath = false' ,
231+ function ( done ) {
232+ testNoAppendPath ( done , false , '.tmp' , null , true ) ;
233+ } ) ;
165234} ) ;
0 commit comments