fix not working stuff
This commit is contained in:
parent
66086b1a91
commit
c6ab3e2466
@ -57,7 +57,7 @@ func HandleFiles(path string, options HandlerOptions, mux *http.ServeMux) {
|
||||
clientVersion: options.ClientVersion,
|
||||
})
|
||||
if options.ActivateLiveReloading {
|
||||
mux.Handle("/_livereloader_", reloader{
|
||||
http.Handle("/_livereloader_", reloader{
|
||||
clientVersion: options.ClientVersion,
|
||||
})
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package spa_handler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
@ -16,11 +17,11 @@ func tryToDeliverFile(file fs.File, path string, w http.ResponseWriter, r *http.
|
||||
http.Error(w, "can not read file", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
modified := []byte{}
|
||||
merge := bytes.NewBuffer([]byte{})
|
||||
for _, a := range appender {
|
||||
modified = append(modified, []byte(a)...)
|
||||
merge.WriteString(a)
|
||||
}
|
||||
modified = append(modified, content...)
|
||||
newContent := strings.Replace(string(content), "</html>", fmt.Sprintf("%s\n</html>", merge.String()), 1)
|
||||
|
||||
stats, statErr := file.Stat()
|
||||
if statErr != nil {
|
||||
@ -33,7 +34,7 @@ func tryToDeliverFile(file fs.File, path string, w http.ResponseWriter, r *http.
|
||||
}
|
||||
contentType = getContentTypeDetail(contentType, stats)
|
||||
|
||||
fileSeeker := bytes.NewReader(modified)
|
||||
fileSeeker := bytes.NewReader([]byte(newContent))
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
http.ServeContent(w, r, path, time.Now(), fileSeeker)
|
||||
}
|
||||
|
||||
@ -9,8 +9,8 @@ import (
|
||||
|
||||
func clientScript(clientVersion string) string {
|
||||
return fmt.Sprintf(`
|
||||
<!-- [spa_handler] Live Reloading Script Start -->
|
||||
<script type="application/javascript">
|
||||
// [spa_handler] live reload script
|
||||
function spaHandlerLiveReloaderConnect() {
|
||||
const ws = new WebSocket("/_livereloader_");
|
||||
ws.onopen = function() {
|
||||
@ -38,11 +38,8 @@ func clientScript(clientVersion string) string {
|
||||
console.warning('[spa_handler]: something was wrong with websocket connection! ', err)
|
||||
};
|
||||
}
|
||||
document.onload = function() {
|
||||
spaHandlerLiveReloaderConnect();
|
||||
};
|
||||
</script>
|
||||
<!-- [spa_handler] Live Reloading Script End -->
|
||||
`, clientVersion)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user