Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit 7a1e757

Browse files
authored
feat: decouple preview localhost resolving on runtime (#21)
1 parent 651b3a5 commit 7a1e757

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/view/PreviewProvider.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ export class PreviewProvider implements WebviewViewProvider {
6262
}
6363
}
6464
})
65+
66+
let serverAddr = `http://127.0.0.1:${config.port}/`
6567

66-
const serverAddr = `http://localhost:${config.port}/`
68+
const indexUrl = `${serverAddr}index.html`
69+
const resolvedBody = await got.get(indexUrl, { responseType: 'text', resolveBodyOnly: true }).catch(() => null)
70+
if (!resolvedBody) {
71+
serverAddr = `http://[::1]:${config.port}/`
72+
}
6773
const url = `${serverAddr}${idx}?embedded=true`
6874

6975
this.view.webview.html = `

0 commit comments

Comments
 (0)