Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions pkg/commands/compute/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ func (c *ServeCommand) Exec(in io.Reader, out io.Writer) (err error) {
text.Break(out)
}

c.setBackendsWithDefaultOverrideHostIfMissing(out)

spinner, err := text.NewSpinner(out)
if err != nil {
return err
Expand Down Expand Up @@ -204,6 +202,10 @@ func (c *ServeCommand) Exec(in io.Reader, out io.Writer) (err error) {
}
}

if err := c.setBackendsWithDefaultOverrideHostIfMissing(out, manifestPath); err != nil {
return err
}

bin, err := c.GetViceroy(spinner, out, manifestPath)
if err != nil {
return err
Expand Down Expand Up @@ -338,7 +340,11 @@ func (c *ServeCommand) Build(in io.Reader, out io.Writer) error {
// local_server.backends that is missing that property. The value will only be
// set if the URL defined uses a hostname (e.g. http://127.0.0.1/ won't) so we
// can set the override_host to match the hostname.
func (c *ServeCommand) setBackendsWithDefaultOverrideHostIfMissing(out io.Writer) {
//
// Viceroy reads backend configuration from the manifest file on disk, so any
// defaults applied here are written back to manifestPath before Viceroy starts.
func (c *ServeCommand) setBackendsWithDefaultOverrideHostIfMissing(out io.Writer, manifestPath string) error {
updated := false
for k, backend := range c.Globals.Manifest.File.LocalServer.Backends {
if backend.OverrideHost == "" {
if u, err := url.Parse(backend.URL); err == nil {
Expand All @@ -349,10 +355,15 @@ func (c *ServeCommand) setBackendsWithDefaultOverrideHostIfMissing(out io.Writer
}
backend.OverrideHost = u.Host
c.Globals.Manifest.File.LocalServer.Backends[k] = backend
updated = true
}
}
}
}
if !updated {
return nil
}
return c.Globals.Manifest.File.Write(manifestPath)
}

// GetViceroy returns the path to the installed binary.
Expand Down
Loading