From: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date: Sat, 23 Sep 2017 15:08:48 +0000 (+0200)
Subject: Add liveReloadPort flag to server
X-Git-Tag: v0.28~12
X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=b18047763;p=brevno-suite%2Fhugo

Add liveReloadPort flag to server

This makes live reloading behind a HTTPS proxy working, as in the example below using the service from https://ngrok.com:

```
hugo server -b https://ba6sdfe72.ngrok.io --appendPort=false --liveReloadPort=443 --navigateToChanged
```

Fixes #3882
---

diff --git a/commands/server.go b/commands/server.go
index 98da568b..b52e38c1 100644
--- a/commands/server.go
+++ b/commands/server.go
@@ -38,6 +38,7 @@ var (
 	serverAppend      bool
 	serverInterface   string
 	serverPort        int
+	liveReloadPort    int
 	serverWatch       bool
 	noHTTPCache       bool
 )
@@ -85,6 +86,7 @@ func init() {
 	initHugoBuilderFlags(serverCmd)
 
 	serverCmd.Flags().IntVarP(&serverPort, "port", "p", 1313, "port on which the server will listen")
+	serverCmd.Flags().IntVar(&liveReloadPort, "liveReloadPort", -1, "port for live reloading (i.e. 443 in HTTPS proxy situations)")
 	serverCmd.Flags().StringVarP(&serverInterface, "bind", "", "127.0.0.1", "interface to which the server will bind")
 	serverCmd.Flags().BoolVarP(&serverWatch, "watch", "w", true, "watch filesystem for changes and recreate as needed")
 	serverCmd.Flags().BoolVar(&noHTTPCache, "noHTTPCache", false, "prevent HTTP caching")
@@ -144,6 +146,11 @@ func server(cmd *cobra.Command, args []string) error {
 	}
 
 	c.Set("port", serverPort)
+	if liveReloadPort != -1 {
+		c.Set("liveReloadPort", liveReloadPort)
+	} else {
+		c.Set("liveReloadPort", serverPort)
+	}
 
 	baseURL, err = fixURL(c.Cfg, baseURL)
 	if err != nil {
diff --git a/hugolib/site.go b/hugolib/site.go
index b8898264..e8b2422b 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -1845,7 +1845,7 @@ func (s *Site) renderAndWritePage(name string, dest string, p *PageOutput, layou
 		}
 
 		if s.running() && s.Cfg.GetBool("watch") && !s.Cfg.GetBool("disableLiveReload") {
-			transformLinks = append(transformLinks, transform.LiveReloadInject(s.Cfg.GetInt("port")))
+			transformLinks = append(transformLinks, transform.LiveReloadInject(s.Cfg.GetInt("liveReloadPort")))
 		}
 
 		// For performance reasons we only inject the Hugo generator tag on the home page.