Skip to content

Commit

Permalink
fix: exclude spa-fallback middleware in middlewareMode (#1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Jan 22, 2021
1 parent 76c4bad commit 843c879
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions packages/vite/src/node/server/index.ts
Expand Up @@ -386,25 +386,27 @@ export async function createServer(
middlewares.use(serveStaticMiddleware(root, config))

// spa fallback
middlewares.use(
history({
logger: createDebugger('vite:spa-fallback'),
// support /dir/ without explicit index.html
rewrites: [
{
from: /\/$/,
to({ parsedUrl }: any) {
const rewritten = parsedUrl.pathname + 'index.html'
if (fs.existsSync(path.join(root, rewritten))) {
return rewritten
} else {
return `/index.html`
if (!middlewareMode) {
middlewares.use(
history({
logger: createDebugger('vite:spa-fallback'),
// support /dir/ without explicit index.html
rewrites: [
{
from: /\/$/,
to({ parsedUrl }: any) {
const rewritten = parsedUrl.pathname + 'index.html'
if (fs.existsSync(path.join(root, rewritten))) {
return rewritten
} else {
return `/index.html`
}
}
}
}
]
})
)
]
})
)
}

// run post config hooks
// This is applied before the html middleware so that user middleware can
Expand Down

0 comments on commit 843c879

Please sign in to comment.