mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-11 07:06:24 +02:00
Allows for serving the web interface from tailscaled, with the ability to start and stop the server via localapi endpoints (/web/start and /web/stop). This will be used to run the new full management web client, which will only be accessible over Tailscale (with an extra auth check step over noise) from the daemon. This switch also allows us to run the web interface securely without needing to manage individual device environments (CGI, proxies, etc). Updates tailscale/corp#14335 Co-authored-by: Will Norris <will@tailscale.com> Signed-off-by: Sonia Appasamy <sonia@tailscale.com> Signed-off-by: Will Norris <will@tailscale.com>
48 lines
933 B
Go
48 lines
933 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{
|
|
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)
|
|
}
|
|
}
|
|
}
|