File tree Expand file tree Collapse file tree 2 files changed +24
-24
lines changed Expand file tree Collapse file tree 2 files changed +24
-24
lines changed Original file line number Diff line number Diff line change @@ -86,15 +86,12 @@ export const serveStatic = <E extends Env = any>(
86
86
const requestPath = options . rewriteRequestPath
87
87
? options . rewriteRequestPath ( filename , c )
88
88
: filename
89
- let path : string
90
-
91
- if ( optionPath ) {
92
- // Use path option directly if specified
93
- path = resolve ( root , optionPath )
94
- } else {
95
- // Build with root + requestPath
96
- path = resolve ( join ( root , requestPath ) )
97
- }
89
+
90
+ let path = optionPath
91
+ ? options . root
92
+ ? resolve ( join ( root , optionPath ) )
93
+ : optionPath
94
+ : resolve ( join ( root , requestPath ) )
98
95
99
96
let stats = getStats ( path )
100
97
Original file line number Diff line number Diff line change @@ -269,23 +269,26 @@ describe('Serve Static Middleware', () => {
269
269
path . join ( __dirname , 'assets' ) ,
270
270
__dirname + path . sep + '..' + path . sep + 'test' + path . sep + 'assets' ,
271
271
]
272
+ const optionPaths = [ 'favicon.ico' , '/favicon.ico' ]
272
273
rootPaths . forEach ( ( root ) => {
273
- describe ( root , ( ) => {
274
- const app = new Hono ( )
275
- const server = createAdaptorServer ( app )
276
-
277
- app . use (
278
- '/favicon.ico' ,
279
- serveStatic ( {
280
- root : './test/assets' ,
281
- path : 'favicon.ico' ,
274
+ optionPaths . forEach ( ( optionPath ) => {
275
+ describe ( `${ root } + ${ optionPath } ` , ( ) => {
276
+ const app = new Hono ( )
277
+ const server = createAdaptorServer ( app )
278
+
279
+ app . use (
280
+ '/favicon.ico' ,
281
+ serveStatic ( {
282
+ root,
283
+ path : optionPath ,
284
+ } )
285
+ )
286
+
287
+ it ( 'Should return 200 response if both root and path set' , async ( ) => {
288
+ const res = await request ( server ) . get ( '/favicon.ico' )
289
+ expect ( res . status ) . toBe ( 200 )
290
+ expect ( res . headers [ 'content-type' ] ) . toBe ( 'image/x-icon' )
282
291
} )
283
- )
284
-
285
- it ( 'Should return 200 response if both root and path set' , async ( ) => {
286
- const res = await request ( server ) . get ( '/favicon.ico' )
287
- expect ( res . status ) . toBe ( 200 )
288
- expect ( res . headers [ 'content-type' ] ) . toBe ( 'image/x-icon' )
289
292
} )
290
293
} )
291
294
} )
You can’t perform that action at this time.
0 commit comments