tailscale/tsnet/example/web-client/web-client.go
Sonia Appasamy 0ecfc1d5c3 client/web: fill devMode from an env var
Avoids the need to pipe a web client dev flag through the tailscaled
command.

Updates tailscale/corp#14335

Signed-off-by: Sonia Appasamy <sonia@tailscale.com>
2023-11-02 21:51:33 -04:00

47 lines
877 B
Go

// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
// The web-client command demonstrates serving the Tailscale web client over tsnet.
package main
import (
"flag"
"log"
"net/http"
"tailscale.com/client/web"
"tailscale.com/tsnet"
)
var (
addr = flag.String("addr", "localhost:8060", "address of Tailscale web client")
)
func main() {
flag.Parse()
s := new(tsnet.Server)
defer s.Close()
lc, err := s.LocalClient()
if err != nil {
log.Fatal(err)
}
// Serve the Tailscale web client.
ws, err := web.NewServer(web.ServerOpts{
Mode: web.LegacyServerMode,
LocalClient: lc,
})
if err != nil {
log.Fatal(err)
}
defer ws.Shutdown()
log.Printf("Serving Tailscale web client on http://%s", *addr)
if err := http.ListenAndServe(*addr, ws); err != nil {
if err != http.ErrServerClosed {
log.Fatal(err)
}
}
}