feat: server playground
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
Reference in New Issue
Block a user