diff --git a/commands/server.go b/commands/server.go index a1605e97cf1..ff8fe4cd294 100644 --- a/commands/server.go +++ b/commands/server.go @@ -168,6 +168,14 @@ func (sc *serverCmd) server(cmd *cobra.Command, args []string) error { c.Set("watch", true) } + // TODO(bep) see issue 9901 + // cfgInit is called twice, before and after the languages have been initialized. + // The servers (below) can not be initialized before we + // know if we're configured in a multihost setup. + if len(c.languages) == 0 { + return nil + } + // We can only do this once. serverCfgInit.Do(func() { c.serverPorts = make([]serverPortListener, 1) diff --git a/commands/server_test.go b/commands/server_test.go index c2aa0dfd5d7..0e4c855da95 100644 --- a/commands/server_test.go +++ b/commands/server_test.go @@ -96,29 +96,47 @@ func TestServerBugs(t *testing.T) { for _, test := range []struct { name string + config string flag string assert func(c *qt.C, r serverTestResult) }{ // Issue 9788 - {"PostProcess, memory", "", func(c *qt.C, r serverTestResult) { + {"PostProcess, memory", "", "", func(c *qt.C, r serverTestResult) { c.Assert(r.err, qt.IsNil) c.Assert(r.homeContent, qt.Contains, "PostProcess: /foo.min.css") }}, - {"PostProcess, disk", "--renderToDisk", func(c *qt.C, r serverTestResult) { + {"PostProcess, disk", "", "--renderToDisk", func(c *qt.C, r serverTestResult) { c.Assert(r.err, qt.IsNil) c.Assert(r.homeContent, qt.Contains, "PostProcess: /foo.min.css") }}, + // Isue 9901 + {"Multihost", ` +defaultContentLanguage = 'en' +[languages] +[languages.en] +baseURL = 'https://example.com' +title = 'My blog' +weight = 1 +[languages.fr] +baseURL = 'https://example.fr' +title = 'Mon blogue' +weight = 2 +`, "", func(c *qt.C, r serverTestResult) { + c.Assert(r.err, qt.IsNil) + }}, } { c.Run(test.name, func(c *qt.C) { - config := ` + if test.config == "" { + test.config = ` baseURL="https://example.org" ` + } var args []string if test.flag != "" { args = strings.Split(test.flag, "=") } - r := runServerTest(c, true, config, args...) + r := runServerTest(c, true, test.config, args...) test.assert(c, r) })