tsnet: add new example serving the Tailscale web client

Updates tailscale/corp#13775

Co-authored-by: Sonia Appasamy <sonia@tailscale.com>
Signed-off-by: Will Norris <will@tailscale.com>
Signed-off-by: Sonia Appasamy <sonia@tailscale.com>
pull/8840/head
Will Norris 9 months ago committed by GitHub
parent 6ee85ba412
commit 3d56cafd7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,44 @@
// 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 (
devMode = flag.Bool("dev", false, "run web client in dev mode")
)
func main() {
flag.Parse()
s := new(tsnet.Server)
defer s.Close()
ln, err := s.Listen("tcp", ":80")
if err != nil {
log.Fatal(err)
}
defer ln.Close()
lc, err := s.LocalClient()
if err != nil {
log.Fatal(err)
}
// Serve the Tailscale web client.
ws := web.NewServer(*devMode, lc)
if err := http.Serve(ln, ws); err != nil {
if err != http.ErrServerClosed {
log.Fatal(err)
}
}
}
Loading…
Cancel
Save