Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: server addr flag is ignored #316

Merged
merged 1 commit into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions .changeset/fix-serve-addr-flag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@empirica/core": patch
---

The `serve` command would ignore the `--addr` flag to specify the address to
listen on. This is now fixed. Thanks to @malsobay for the report. Fixes #315.
4 changes: 0 additions & 4 deletions cmds/empirica/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ func addServeCommand(parent *cobra.Command) error {
conf := getConfig()
conf.Server.Addr = addr

conf.Production = !devMode
conf.Server.Production = !devMode
conf.Tajriba.Server.Production = !devMode

return bundle.Serve(ctx, conf, in, clean, devMode)
},
}
Expand Down
21 changes: 16 additions & 5 deletions internal/bundle/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,24 @@ func Serve(ctx context.Context, config *empirica.Config, in string, clean, devMo
}

var args []string
cmd := parts[0]
if len(parts) > 1 {
args = parts[1:]
if parts[0] == "npm" {
cmd = "empirica"
args = parts
} else {
args = parts[1:]
}
}

args = append(args, "--token", conf.Callbacks.Token)

addr := conf.Server.Addr
if strings.HasPrefix(addr, ":") {
addr = "http://localhost" + addr + "/query"
}
args = append(args, "--url", addr)

if conf.Callbacks.SessionToken != "" {
p := conf.Callbacks.SessionToken
if !strings.HasPrefix(p, "/") {
Expand All @@ -59,12 +71,11 @@ func Serve(ctx context.Context, config *empirica.Config, in string, clean, devMo
args = append(args, "--sessionTokenPath", p)
}

log.Trace().
Strs("args", args).
Str("cmd", parts[0]).
log.Debug().
Str("cmd", strings.Join(append([]string{cmd}, args...), " ")).
Msg("serve: start server command")

c := exec.CommandContext(ctx, parts[0], args...)
c := exec.CommandContext(ctx, cmd, args...)

p := path.Join(dir, "callbacks")

Expand Down
5 changes: 5 additions & 0 deletions internal/bundle/unbundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"

"github.com/empiricaly/empirica"
"github.com/empiricaly/empirica/internal/server"
"github.com/empiricaly/empirica/internal/settings"
"github.com/klauspost/compress/gzip"
"github.com/klauspost/compress/zstd"
Expand Down Expand Up @@ -82,6 +83,10 @@ func prepDotEmpirica(inConf *empirica.Config, dir string, devMode bool) (*empiri
conf.Server.Production = !devMode
conf.Tajriba.Server.Production = !devMode

if conf.Server.Addr == server.DefaultAddr {
conf.Server.Addr = inConf.Server.Addr
}

if inConf.Tajriba.Store.UseMemory {
conf.Tajriba.Store.UseMemory = true
}
Expand Down
4 changes: 3 additions & 1 deletion internal/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func (c *Config) Validate() error {
return nil
}

const DefaultAddr = ":3000"

// ConfigFlags helps configure cobra and viper flags.
func ConfigFlags(cmd *cobra.Command, prefix string) error {
if cmd == nil {
Expand All @@ -39,7 +41,7 @@ func ConfigFlags(cmd *cobra.Command, prefix string) error {
viper.SetDefault(prefix, &Config{})

flag := prefix + ".addr"
sval := ":3000"
sval := DefaultAddr
cmd.Flags().StringP(flag, "s", sval, "Address of the server")
viper.SetDefault(flag, sval)

Expand Down