Skip to content

Commit

Permalink
server: Fix multihost crash
Browse files Browse the repository at this point in the history
As introduced in v0.99.0.

Fixes #9901
  • Loading branch information
bep committed May 18, 2022
1 parent 3a8189e commit 0835ba0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
8 changes: 8 additions & 0 deletions commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 22 additions & 4 deletions commands/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

})
Expand Down

0 comments on commit 0835ba0

Please sign in to comment.