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 (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"tailscale.com/client/web"
|
|
|
|
"tailscale.com/tsnet"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-11-02 22:19:16 +00:00
|
|
|
addr = flag.String("addr", "localhost:8060", "address of Tailscale web client")
|
2023-08-10 15:34:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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.
|
2023-10-11 18:35:22 +00:00
|
|
|
ws, err := web.NewServer(web.ServerOpts{
|
2023-11-15 21:50:03 +00:00
|
|
|
Mode: web.LoginServerMode,
|
2023-08-23 22:22:24 +00:00
|
|
|
LocalClient: lc,
|
|
|
|
})
|
2023-10-11 18:35:22 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer ws.Shutdown()
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|