2017-06-22 23:37:46 +02:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2017-06-23 15:32:08 +02:00
|
|
|
|
|
|
|
"github.com/jaschaephraim/lrserver"
|
2017-06-22 23:37:46 +02:00
|
|
|
)
|
|
|
|
|
2017-06-23 15:32:08 +02:00
|
|
|
// liveReloadScriptTag is inserted into the HTML page.
|
2017-06-22 23:37:46 +02:00
|
|
|
var liveReloadScriptTag = []byte(`<script src="http://localhost:35729/livereload.js"></script>`)
|
|
|
|
|
2017-06-23 15:32:08 +02:00
|
|
|
// StartLiveReloader starts the Live Reload server as a go routine, and returns immediately
|
|
|
|
func (s *Server) StartLiveReloader() error {
|
|
|
|
s.lr = lrserver.New(lrserver.DefaultName, lrserver.DefaultPort)
|
|
|
|
s.lr.SetStatusLog(nil)
|
|
|
|
go s.lr.ListenAndServe() // nolint: errcheck
|
|
|
|
return nil
|
2017-06-22 23:37:46 +02:00
|
|
|
}
|
|
|
|
|
2017-06-22 23:53:46 +02:00
|
|
|
// NewLiveReloadInjector returns a writer that injects the Live Reload JavaScript
|
2017-06-22 23:37:46 +02:00
|
|
|
// into its wrapped content.
|
|
|
|
func NewLiveReloadInjector(w io.Writer) io.Writer {
|
|
|
|
return TagInjector{w, liveReloadScriptTag}
|
|
|
|
}
|