Skip to content

Commit 7e091e0

Browse files
committed
wip: full bundle dev env
1 parent 7e9e6c8 commit 7e091e0

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

packages/vite/src/node/server/middlewares/htmlFallback.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'node:path'
22
import fs from 'node:fs'
33
import type { Connect } from 'dep-types/connect'
4-
import { createDebugger } from '../../utils'
4+
import { createDebugger, joinUrlSegments } from '../../utils'
55
import { cleanUrl } from '../../../shared/utils'
66
import type { DevEnvironment } from '../environment'
77
import { 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

packages/vite/src/node/server/middlewares/indexHtml.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,10 @@ export function indexHtmlMiddleware(
457457
// htmlFallbackMiddleware appends '.html' to URLs
458458
if (url?.endsWith('.html') && req.headers['sec-fetch-dest'] !== 'script') {
459459
if (fullBundleEnv) {
460-
const cleanedUrl = cleanUrl(url).slice(1) // remove first /
461-
let content = fullBundleEnv.memoryFiles.get(cleanedUrl)
460+
const pathname = decodeURIComponent(url)
461+
const filePath = pathname.slice(1) // remove first /
462+
463+
let content = fullBundleEnv.memoryFiles.get(filePath)
462464
if (!content && fullBundleEnv.memoryFiles.size !== 0) {
463465
return next()
464466
}

packages/vite/src/node/server/middlewares/memoryFiles.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)