2023-08-10 15:34:33 +00:00
|
|
|
// 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 (
|
2023-08-24 20:24:57 +00:00
|
|
|
"context"
|
2023-08-10 15:34:33 +00:00
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"tailscale.com/client/web"
|
|
|
|
"tailscale.com/tsnet"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-08-18 21:19:41 +00:00
|
|
|
addr = flag.String("addr", "localhost:8060", "address of Tailscale web client")
|
2023-08-10 15:34:33 +00:00
|
|
|
devMode = flag.Bool("dev", false, "run web client in dev mode")
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
2023-08-24 20:24:57 +00:00
|
|
|
ctx := context.Background()
|
2023-08-10 15:34:33 +00:00
|
|
|
|
|
|
|
s := new(tsnet.Server)
|
|
|
|
defer s.Close()
|
|
|
|
|
|
|
|
lc, err := s.LocalClient()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serve the Tailscale web client.
|
2023-08-24 20:24:57 +00:00
|
|
|
ws, cleanup := web.NewServer(ctx, web.ServerOpts{
|
2023-08-23 22:22:24 +00:00
|
|
|
DevMode: *devMode,
|
|
|
|
LocalClient: lc,
|
|
|
|
})
|
2023-08-10 17:58:59 +00:00
|
|
|
defer cleanup()
|
2023-08-18 21:19:41 +00:00
|
|
|
log.Printf("Serving Tailscale web client on http://%s", *addr)
|
|
|
|
if err := http.ListenAndServe(*addr, ws); err != nil {
|
2023-08-10 15:34:33 +00:00
|
|
|
if err != http.ErrServerClosed {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|