use location instead of hardcoded url in livereload snippets

This commit is contained in:
facundoolano 2024-03-05 16:34:16 -03:00
parent 98eb2cd556
commit 6f480dee98
2 changed files with 6 additions and 6 deletions

View file

@ -193,10 +193,10 @@ func (site *site) build() error {
return os.MkdirAll(targetPath, FILE_RW_MODE)
}
- // if it's a file render or copy it at the target
- // if it's a file render or copy it to the target
- return site.buildFile(path, targetPath)
+ // if it's a file send the path to a worker
+ // to render or copy it at the target
+ // to render or copy it to the target
+ files <- path
+ return nil
})
@ -249,7 +249,8 @@ var eventSource;
function newSSE() {
console.log("connecting to server events");
eventSource = new EventSource('http://localhost:4001/_events/');
const url = location.origin + '/_events/';
eventSource = new EventSource(url);
// when the server sends an event, refresh the page
eventSource.onmessage = function () {

View file

@ -434,7 +434,7 @@ func (site *site) injectLiveReload(extension string, contentReader io.Reader) (i
}
const JS_SNIPPET = `
const url = '%s/_events/'
const url = location.origin + '/_events/'
var eventSource;
function newSSE() {
console.log("connecting to server events");
@ -452,6 +452,5 @@ function newSSE() {
};
}
newSSE();`
script := fmt.Sprintf(JS_SNIPPET, site.config.SiteUrl)
return markup.InjectScript(contentReader, script)
return markup.InjectScript(contentReader, JS_SNIPPET)
}