Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: decode url for middleware #4728

Merged
merged 14 commits into from Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/vite/src/node/server/index.ts
Expand Up @@ -21,6 +21,7 @@ import {
indexHtmlMiddleware
} from './middlewares/indexHtml'
import history from 'connect-history-api-fallback'
import { decodeURIMiddleware } from './middlewares/decodeURI'
import {
serveRawFsMiddleware,
servePublicMiddleware,
Expand Down Expand Up @@ -486,6 +487,9 @@ export async function createServer(
res.end('pong')
})

//decode request url
hannoeru marked this conversation as resolved.
Show resolved Hide resolved
middlewares.use(decodeURIMiddleware())

// serve static files under /public
// this applies before the transform middleware so that these files are served
// as-is without transforms.
Expand Down
10 changes: 10 additions & 0 deletions packages/vite/src/node/server/middlewares/decodeURI.ts
@@ -0,0 +1,10 @@
import { Connect } from 'types/connect'
hannoeru marked this conversation as resolved.
Show resolved Hide resolved

export function decodeURIMiddleware(): Connect.NextHandleFunction {
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
return function viteDecoreURIMiddleware(req, _, next) {
hannoeru marked this conversation as resolved.
Show resolved Hide resolved
// #2195
req.url = decodeURI(req.url!)
next()
}
}