-
Notifications
You must be signed in to change notification settings - Fork 6
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: Compare only the URL path component to expected value when proxying HMR websocket (fix #53) #52
Conversation
…oxying HMR websocket
} | ||
|
||
function isHMRProxyRequest(req: IncomingMessage) { | ||
const url = new URL(`http://example.com${req.url}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL constructor have a native (more robust) way to handle URL base. See https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#parameters
const url = new URL(`http://example.com${req.url}`) | |
const url = new URL(req.url, "http://example.com") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out this commit which switched to use the two argument constructor as you suggested.
The case where req.url === undefined
is handled explicitly.
Semantics remain the same if one assumes VITE_HMR_PATH
to always be a path starting with /
.
👍 It doesn't conflict so feel free to merge whenever you want. I recommend to edit the title of this PR to add the |
Also for appending |
I don't have any major code refactoring going on for Vike extensions. (Only transforming them into real Vike extensions, which should't conflict with other changes.) |
…ssing req.url explicitly as a non-match, whereas previously url.pathname would have implicitly resolved to '/'.
I added the prefix and issue reference to the PR title. |
Released as |
I reverted the peer dep version change (a0a2b38). (It's a small breaking change. Personally I think it's fine for a @magne4000 I went ahead and applied the optional peer dep trick: 4ab3b87. @magne4000 @snake-py I've just seen that Vite exports |
In versions 5.4.12 and 6.0.9 vite introduced several fixes to vulnerabilities in HMR websocket.
Amongst other changes, a query parameter
token
was added to the HMR websocket upgrade request.This broke the HMR proxy feature in
vike-node
. Socket connection was not established, and the browser request was left pending until timing out.This PR suggests a backwards compatible approach to accommodate these changes.
Following steps were taken:
devServerPlugin.ts
vite
dependencies to the minimum patch version with the aforementioned security fixes in allpackage.json
-filespnpm install && pnpm run build && pnpm run test
and confirm successful runpackage.json
-files and runpnpm run reset && pnpm install && pnpm run build && pnpm run test
to confirm successful run with previously usedvite
versionspackage.json
modifications are not necessary to fix the issue, but are included for replicating the steps above