commit 7a8b754cada398241fc2d58d63ce58551f6c734c
parent 4076d77029e0705f9e9aa43a347b033dbc2d3cc9
Author: spf13 <steve.francia@gmail.com>
Date: Wed, 28 May 2014 19:01:24 -0400
Fixed #301. LiveReload works on any port now.
Diffstat:
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/commands/server.go b/commands/server.go
@@ -83,6 +83,8 @@ func server(cmd *cobra.Command, args []string) {
serverPort = sp.Port
}
+ viper.Set("port", serverPort)
+
if serverAppend {
viper.Set("BaseUrl", strings.TrimSuffix(BaseUrl, "/")+":"+strconv.Itoa(serverPort))
} else {
diff --git a/transform/livereloadinject.go b/transform/livereloadinject.go
@@ -1,12 +1,17 @@
package transform
-import "bytes"
+import (
+ "bytes"
+
+ "github.com/spf13/viper"
+)
func LiveReloadInject(content []byte) []byte {
match := []byte("</body>")
+ port := viper.GetString("port")
replace := []byte(`<script>document.write('<script src="http://'
+ (location.host || 'localhost').split(':')[0]
- + ':1313/livereload.js?mindelay=10"></'
+ + ':` + port + `/livereload.js?mindelay=10"></'
+ 'script>')</script></body>`)
newcontent := bytes.Replace(content, match, replace, -1)