yandeu / five-server

⚡ Development Server with Live Reload Capability. (Maintained Fork of Live Server)
https://www.npmjs.com/package/five-server
Other
162 stars 14 forks source link

WebSocket connection fails when url doesn't end with / #32

Closed saitonakamura closed 2 years ago

saitonakamura commented 2 years ago

Describe the bug When route doesn't end with / (say /my/route), this line doesn't replace it with /fwsw. I also don't understand what is the idea behind replacing part of pathname instead of just using /fsws after the host

yandeu commented 2 years ago

Like this?

  // https://github.com/yandeu/five-server/blob/main/client/injected.ts

  const script = document.querySelector('[data-id="five-server"]') as HTMLScriptElement
  const protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'
- const address = `${protocol}${new URL(script.src).host}${window.location.pathname.replace(/\/+$/gm, '/fsws')}`
+ const address = `${protocol}${new URL(script.src).host}/fsws`
saitonakamura commented 2 years ago

Yeah. Cause maybe I'm missing something

yandeu commented 2 years ago

I can't remember why I did this. All tests are passing.

yandeu commented 2 years ago

Found it https://github.com/yandeu/five-server/commit/4a3327b2ddbcac41b92bffd2fff1d5b2dcdb9d03#diff-4a1eadd1b9a9e08a65cbc0cca97b8ec321f7a33ded736e102fbcbfd167865757

yandeu commented 2 years ago

Fixed in #32

saitonakamura commented 2 years ago

@yandeu thanks! Would be so kind and release it to npm?

yandeu commented 2 years ago

Done

saitonakamura commented 2 years ago

Great, ty!