Skip to content

Commit

Permalink
refactor: deploy mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peefy committed Feb 9, 2023
1 parent a367d25 commit fa1b586
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ COPY --from=builder /app/kcl-playground .
EXPOSE 2022


CMD ["./kcl-playground"]
CMD ["./kcl-playground -deploy"]
41 changes: 36 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,47 @@
package main

import (
"flag"
"fmt"
"os/exec"
"runtime"
"strings"
"time"

"kusionstack.io/kcl-playground/pkg/play"
)

func main() {
addr := ":2022"
fmt.Printf("listen at http://%s\n", addr)

play.Run(addr, &play.Option{
deploy_mode := flag.Bool("deploy", false, "Whether is deploy mode")
flag.Parse()
opt := play.Option{
PlayMode: true,
})
}
if *deploy_mode {
play.Run(":80", &opt)
} else {
addr := "localhost:2023"
fmt.Printf("listen at http://%s\n", addr)
go func() {
time.Sleep(time.Second * 2)
openBrowser(addr)
}()
play.Run(addr, &opt)
}
}

func openBrowser(url string) error {
if !strings.HasPrefix(url, "http") {
url = "http://" + url
}
switch runtime.GOOS {
case "linux":
return exec.Command("xdg-open", url).Start()
case "windows":
return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
return exec.Command("open", url).Start()
default:
return fmt.Errorf("unsupported platform")
}
}

0 comments on commit fa1b586

Please sign in to comment.