File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
packages/vite/src/node/server/middlewares Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -63,8 +63,20 @@ export function htmlFallbackMiddleware(
63
63
}
64
64
65
65
if ( spaFallback ) {
66
- debug ?.( `Rewriting ${ req . method } ${ req . url } to /index.html` )
67
- req . url = '/index.html'
66
+ // remove a path component at a time from pathname and check for
67
+ // the presence of a corresponding index.html
68
+ let workingPathname = pathname
69
+ while ( true ) {
70
+ const filePath = path . join ( root , workingPathname , 'index.html' )
71
+ if ( fs . existsSync ( filePath ) ) {
72
+ const newUrl = workingPathname + '/index.html'
73
+ debug ?.( `Rewriting ${ req . method } ${ req . url } to ${ newUrl } ` )
74
+ req . url = newUrl
75
+ return next ( )
76
+ }
77
+ if ( workingPathname === '/' ) break
78
+ workingPathname = path . dirname ( workingPathname )
79
+ }
68
80
}
69
81
70
82
next ( )
You can’t perform that action at this time.
0 commit comments