feat: server playground

This commit is contained in:
Max Richter
2025-10-05 23:52:31 +02:00
parent 6d92c92797
commit 5adc3a3cc1
24 changed files with 805 additions and 1 deletions

View File

@@ -24,8 +24,21 @@ func main() {
var roots multi
flag.Var(&roots, "root", "repeatable; specify multiple -root flags")
addr := flag.String("addr", ":8080", "listen address")
playgroundRoot := flag.String("playground-root", "", "path to playground build directory")
flag.Parse()
if *playgroundRoot != "" {
absPlaygroundRoot, err := filepath.Abs(*playgroundRoot)
must(err)
info, err := os.Stat(absPlaygroundRoot)
must(err)
if !info.IsDir() {
log.Fatalf("playground-root %s is not a directory", *playgroundRoot)
}
log.Printf("serving playground from %s", absPlaygroundRoot)
http.Handle("/_playground/", http.StripPrefix("/_playground/", http.FileServer(http.Dir(absPlaygroundRoot))))
}
if len(roots) == 0 {
log.Fatal("at least one -root flag must be specified")
}