tailscale/tsnet/example/web-client/web-client.go
Sonia Appasamy 191e2ce719 client/web: add ServerMode to web.Server
Adds a new Mode to the web server, indicating the specific
scenario the constructed server is intended to be run in. Also
starts filling this from the cli/web and ipn/ipnlocal callers.

From cli/web this gets filled conditionally based on whether the
preview web client node cap is set. If not set, the existing
"legacy" client is served. If set, both a login/lobby and full
management client are started (in "login" and "manage" modes
respectively).

Updates tailscale/corp#14335

Signed-off-by: Sonia Appasamy <sonia@tailscale.com>
2023-11-02 17:20:05 -04:00

49 lines
970 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")
devMode = flag.Bool("dev", false, "run web client in dev mode")
)
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,
DevMode: *devMode,
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)
}
}
}