Skip to content

Commit

Permalink
fix(PreviewServer): serialize IPv6 host correctly in URL
Browse files Browse the repository at this point in the history
* Ensure IPv6 host is surrounded by square brackets when
serialized into a URL
* Use the Node-provided `family` property of the address
returned by `.listen()` to check whether the address is
IPv6, instead of relying on guesswork of looking at the IP
  • Loading branch information
milesrichardson committed Aug 29, 2022
1 parent 4fbe7d0 commit 3e48ce2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/server/PreviewServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ export class PreviewServer {
this.log('establishing server connection...')

const connection = this.app.listen(port, host, () => {
const { address, port } = connection.address() as AddressInfo
const url = `http://${address}:${port}`
const { address, port, family } = connection.address() as AddressInfo
// IPv6 host requires surrounding square brackets when serialized to URL
// note: IPv6 host can take many forms, e.g. `::` and `::1` are both ok
const url = `http://${
family === 'IPv6' ? `[${address}]` : address
}:${port}`
this.connectionInfo = {
port,
host: address,
Expand Down

0 comments on commit 3e48ce2

Please sign in to comment.