@@ -145,6 +145,9 @@ func server(cmd *cobra.Command, args []string) error {
145145 serverPorts := make ([]int , 1 )
146146
147147 if languages .IsMultihost () {
148+ if ! serverAppend {
149+ return newSystemError ("--appendPort=false not supported when in multihost mode" )
150+ }
148151 serverPorts = make ([]int , len (languages ))
149152 }
150153
@@ -171,6 +174,8 @@ func server(cmd *cobra.Command, args []string) error {
171174 currentServerPort = serverPorts [i ] + 1
172175 }
173176
177+ c .serverPorts = serverPorts
178+
174179 c .Set ("port" , serverPort )
175180 if liveReloadPort != - 1 {
176181 c .Set ("liveReloadPort" , liveReloadPort )
@@ -246,16 +251,15 @@ func server(cmd *cobra.Command, args []string) error {
246251}
247252
248253type fileServer struct {
249- ports []int
250254 baseURLs []string
251255 roots []string
252256 c * commandeer
253257}
254258
255- func (f * fileServer ) createEndpoint (i int ) (* http.ServeMux , string , error ) {
259+ func (f * fileServer ) createEndpoint (i int ) (* http.ServeMux , string , string , error ) {
256260 baseURL := f .baseURLs [i ]
257261 root := f .roots [i ]
258- port := f .ports [i ]
262+ port := f .c . serverPorts [i ]
259263
260264 publishDir := f .c .Cfg .GetString ("publishDir" )
261265
@@ -286,7 +290,7 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, string, error) {
286290 // We're only interested in the path
287291 u , err := url .Parse (baseURL )
288292 if err != nil {
289- return nil , "" , fmt .Errorf ("Invalid baseURL: %s" , err )
293+ return nil , "" , "" , fmt .Errorf ("Invalid baseURL: %s" , err )
290294 }
291295
292296 decorate := func (h http.Handler ) http.Handler {
@@ -317,7 +321,7 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, string, error) {
317321
318322 endpoint := net .JoinHostPort (serverInterface , strconv .Itoa (port ))
319323
320- return mu , endpoint , nil
324+ return mu , u . String (), endpoint , nil
321325}
322326
323327func (c * commandeer ) serve () {
@@ -327,24 +331,20 @@ func (c *commandeer) serve() {
327331 var (
328332 baseURLs []string
329333 roots []string
330- ports []int
331334 )
332335
333336 if isMultiHost {
334337 for _ , s := range Hugo .Sites {
335338 baseURLs = append (baseURLs , s .BaseURL .String ())
336339 roots = append (roots , s .Language .Lang )
337- ports = append (ports , s .Info .ServerPort ())
338340 }
339341 } else {
340342 s := Hugo .Sites [0 ]
341343 baseURLs = []string {s .BaseURL .String ()}
342344 roots = []string {"" }
343- ports = append (ports , s .Info .ServerPort ())
344345 }
345346
346347 srv := & fileServer {
347- ports : ports ,
348348 baseURLs : baseURLs ,
349349 roots : roots ,
350350 c : c ,
@@ -357,13 +357,13 @@ func (c *commandeer) serve() {
357357 }
358358
359359 for i , _ := range baseURLs {
360- mu , endpoint , err := srv .createEndpoint (i )
360+ mu , serverURL , endpoint , err := srv .createEndpoint (i )
361361
362362 if doLiveReload {
363363 mu .HandleFunc ("/livereload.js" , livereload .ServeJS )
364364 mu .HandleFunc ("/livereload" , livereload .Handler )
365365 }
366- jww .FEEDBACK .Printf ("Web Server is available at %s (bind address %s)\n " , endpoint , serverInterface )
366+ jww .FEEDBACK .Printf ("Web Server is available at %s (bind address %s)\n " , serverURL , serverInterface )
367367 go func () {
368368 err = http .ListenAndServe (endpoint , mu )
369369 if err != nil {
0 commit comments