dev command local server
This commit is contained in:
29
main.go
29
main.go
@@ -262,6 +262,22 @@ func runDev() error {
|
||||
return err
|
||||
}
|
||||
|
||||
configPath := filepath.Join(cwd, "pb.toml")
|
||||
cfg, err := loadPBConfig(configPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
serviceName := strings.TrimSpace(cfg.PocketBase.ServiceName)
|
||||
if serviceName == "" {
|
||||
return fmt.Errorf("pb.toml missing [pocketbase].service")
|
||||
}
|
||||
|
||||
port := cfg.Server.Port
|
||||
if port <= 0 {
|
||||
port = 8090
|
||||
}
|
||||
|
||||
binaryPath := filepath.Join(cwd, pocketbaseBinaryName(runtime.GOOS))
|
||||
if err := ensurePocketbaseBinary(defaultPocketbaseVersion, runtime.GOOS, runtime.GOARCH, binaryPath); err != nil {
|
||||
return err
|
||||
@@ -271,8 +287,19 @@ func runDev() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if overrides == nil {
|
||||
overrides = make(map[string]string)
|
||||
}
|
||||
|
||||
cmd := exec.Command(binaryPath, "serve")
|
||||
portValue := strings.TrimSpace(overrides["PORT"])
|
||||
if portValue == "" {
|
||||
portValue = strconv.Itoa(port)
|
||||
overrides["PORT"] = portValue
|
||||
}
|
||||
|
||||
httpAddr := fmt.Sprintf("%s.localhost:%s", serviceName, portValue)
|
||||
|
||||
cmd := exec.Command(binaryPath, "serve", fmt.Sprintf("--http=%s", httpAddr))
|
||||
cmd.Dir = cwd
|
||||
cmd.Env = mergeEnv(overrides)
|
||||
cmd.Stdout = os.Stdout
|
||||
|
||||
Reference in New Issue
Block a user