File tree Expand file tree Collapse file tree 3 files changed +16
-9
lines changed
packages/vite/src/node/server/middlewares Expand file tree Collapse file tree 3 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 11import path from 'node:path'
22import fs from 'node:fs'
33import type { Connect } from 'dep-types/connect'
4- import { createDebugger } from '../../utils'
4+ import { createDebugger , joinUrlSegments } from '../../utils'
55import { cleanUrl } from '../../../shared/utils'
66import type { DevEnvironment } from '../environment'
77import { FullBundleDevEnvironment } from '../environments/fullBundleEnvironment'
@@ -20,8 +20,9 @@ export function htmlFallbackMiddleware(
2020
2121 function checkFileExists ( relativePath : string ) {
2222 return (
23- memoryFiles ?. has ( relativePath ) ??
24- fs . existsSync ( path . join ( root , relativePath ) )
23+ memoryFiles ?. has (
24+ relativePath . slice ( 1 ) , // remove first /
25+ ) ?? fs . existsSync ( path . join ( root , relativePath ) )
2526 )
2627 }
2728
@@ -57,7 +58,7 @@ export function htmlFallbackMiddleware(
5758 }
5859 // trailing slash should check for fallback index.html
5960 else if ( pathname . endsWith ( '/' ) ) {
60- if ( checkFileExists ( path . join ( pathname , 'index.html' ) ) ) {
61+ if ( checkFileExists ( joinUrlSegments ( pathname , 'index.html' ) ) ) {
6162 const newUrl = url + 'index.html'
6263 debug ?.( `Rewriting ${ req . method } ${ req . url } to ${ newUrl } ` )
6364 req . url = newUrl
Original file line number Diff line number Diff line change @@ -459,8 +459,10 @@ export function indexHtmlMiddleware(
459459 // htmlFallbackMiddleware appends '.html' to URLs
460460 if ( url ?. endsWith ( '.html' ) && req . headers [ 'sec-fetch-dest' ] !== 'script' ) {
461461 if ( fullBundleEnv ) {
462- const cleanedUrl = cleanUrl ( url ) . slice ( 1 ) // remove first /
463- let content = fullBundleEnv . memoryFiles . get ( cleanedUrl )
462+ const pathname = decodeURIComponent ( url )
463+ const filePath = pathname . slice ( 1 ) // remove first /
464+
465+ let content = fullBundleEnv . memoryFiles . get ( filePath )
464466 if ( ! content && fullBundleEnv . memoryFiles . size !== 0 ) {
465467 return next ( )
466468 }
Original file line number Diff line number Diff line change @@ -17,13 +17,17 @@ export function memoryFilesMiddleware(
1717 const headers = server . config . server . headers
1818
1919 return function viteMemoryFilesMiddleware ( req , res , next ) {
20- const cleanedUrl = cleanUrl ( req . url ! ) . slice ( 1 ) // remove first /
20+ const cleanedUrl = cleanUrl ( req . url ! )
2121 if ( cleanedUrl . endsWith ( '.html' ) ) {
2222 return next ( )
2323 }
24- const file = memoryFiles . get ( cleanedUrl )
24+
25+ const pathname = decodeURIComponent ( cleanedUrl )
26+ const filePath = pathname . slice ( 1 ) // remove first /
27+
28+ const file = memoryFiles . get ( filePath )
2529 if ( file ) {
26- const mime = mrmime . lookup ( cleanedUrl )
30+ const mime = mrmime . lookup ( filePath )
2731 if ( mime ) {
2832 res . setHeader ( 'Content-Type' , mime )
2933 }
You can’t perform that action at this time.
0 commit comments