Skip to content

Commit

Permalink
Use web page address when making request to reload proxy (#625)
Browse files Browse the repository at this point in the history
* Use web page address when making request to reload proxy

Signed-off-by: Alexandra Fishova <yopoyka@yopoyka.com>

* Create event source with just a path because browser can handle address on its own.

Signed-off-by: Alexandra Fishova <yopoyka@yopoyka.com>

---------

Signed-off-by: Alexandra Fishova <yopoyka@yopoyka.com>
  • Loading branch information
yopoyka authored Sep 21, 2024
1 parent f4f7c3d commit 6761441
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions runner/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ func (p *Proxy) injectLiveReload(resp *http.Response) (string, error) {
return page, nil
}

script := fmt.Sprintf(
`<script>new EventSource("http://localhost:%d/internal/reload").onmessage = () => { location.reload() }</script>`,
p.config.ProxyPort,
)
script := `<script>new EventSource("/internal/reload").onmessage = () => { location.reload() }</script>`
return page[:body] + script + page[body:], nil
}

Expand Down
2 changes: 1 addition & 1 deletion runner/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestProxy_injectLiveReload(t *testing.T) {
},
Body: io.NopCloser(strings.NewReader(`<body><h1>test</h1></body>`)),
},
expect: `<body><h1>test</h1><script>new EventSource("http://localhost:1111/internal/reload").onmessage = () => { location.reload() }</script></body>`,
expect: `<body><h1>test</h1><script>new EventSource("/internal/reload").onmessage = () => { location.reload() }</script></body>`,
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 6761441

Please sign in to comment.