hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 1abc2f0b8663a3082c509157952bb756bcd38f92
parent a10519643d58abe823c17f3d4cd3a9dd26f89403
Author: Matt Way <git@mway.me>
Date:   Fri, 22 Nov 2013 00:28:05 -0500

properly use non-localhost BaseUrl in server command

Diffstat:
Mcommands/server.go | 12+++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/commands/server.go b/commands/server.go
@@ -18,6 +18,7 @@ import (
 	"github.com/spf13/cobra"
 	"net/http"
 	"strconv"
+	"strings"
 )
 
 var serverPort int
@@ -40,11 +41,16 @@ Serve them up.`,
 func server(cmd *cobra.Command, args []string) {
 	InitializeConfig()
 
-	// Unless command line overrides, we use localhost for the server
 	if BaseUrl == "" {
-		Config.BaseUrl = "http://localhost:" + strconv.Itoa(serverPort)
+		BaseUrl = "http://localhost"
 	}
 
+	if !strings.HasPrefix(BaseUrl, "http://") {
+		BaseUrl = "http://" + BaseUrl
+	}
+
+	Config.BaseUrl = strings.TrimSuffix(BaseUrl, "/") + ":" + strconv.Itoa(serverPort)
+
 	build(serverWatch)
 
 	// Watch runs its own server as part of the routine
@@ -64,7 +70,7 @@ func serve(port int) {
 		fmt.Println("Serving pages from " + Config.GetAbsPath(Config.PublishDir))
 	}
 
-	fmt.Printf("Web Server is available at http://localhost:%v\n", port)
+	fmt.Printf("Web server is available at %s\n", Config.BaseUrl)
 	fmt.Println("Press ctrl+c to stop")
 	panic(http.ListenAndServe(":"+strconv.Itoa(port), http.FileServer(http.Dir(Config.GetAbsPath(Config.PublishDir)))))
 }