From 0ecfc1d5c3c27299c79ac9907c9d84ef7384b681 Mon Sep 17 00:00:00 2001 From: Sonia Appasamy Date: Thu, 2 Nov 2023 18:19:16 -0400 Subject: [PATCH] client/web: fill devMode from an env var Avoids the need to pipe a web client dev flag through the tailscaled command. Updates tailscale/corp#14335 Signed-off-by: Sonia Appasamy --- client/web/web.go | 12 +++++------- cmd/tailscale/cli/web.go | 3 --- ipn/ipnlocal/web_client.go | 5 ++--- tsnet/example/web-client/web-client.go | 4 +--- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/client/web/web.go b/client/web/web.go index 217c1c686..cc902fe15 100644 --- a/client/web/web.go +++ b/client/web/web.go @@ -43,6 +43,9 @@ type Server struct { lc *tailscale.LocalClient timeNow func() time.Time + // devMode indicates that the server run with frontend assets + // served by a Vite dev server, allowing for local development + // on the web client frontend. devMode bool cgiMode bool pathPrefix string @@ -100,11 +103,6 @@ type ServerOpts struct { // Mode specifies the mode of web client being constructed. Mode ServerMode - // DevMode indicates that the server should be started with frontend - // assets served by a Vite dev server, allowing for local development - // on the web client frontend. - DevMode bool - // CGIMode indicates if the server is running as a CGI script. CGIMode bool @@ -143,7 +141,7 @@ func NewServer(opts ServerOpts) (s *Server, err error) { s = &Server{ mode: opts.Mode, logf: opts.Logf, - devMode: opts.DevMode, + devMode: envknob.Bool("TS_DEBUG_WEB_CLIENT_DEV"), lc: opts.LocalClient, cgiMode: opts.CGIMode, pathPrefix: opts.PathPrefix, @@ -155,7 +153,7 @@ func NewServer(opts ServerOpts) (s *Server, err error) { if s.logf == nil { s.logf = log.Printf } - s.assetsHandler, s.assetsCleanup = assetsHandler(opts.DevMode) + s.assetsHandler, s.assetsCleanup = assetsHandler(s.devMode) var metric string // clientmetric to report on startup diff --git a/cmd/tailscale/cli/web.go b/cmd/tailscale/cli/web.go index 7c92c38ed..f59905510 100644 --- a/cmd/tailscale/cli/web.go +++ b/cmd/tailscale/cli/web.go @@ -41,7 +41,6 @@ Tailscale, as opposed to a CLI or a native app. webf := newFlagSet("web") webf.StringVar(&webArgs.listen, "listen", "localhost:8088", "listen address; use port 0 for automatic") webf.BoolVar(&webArgs.cgi, "cgi", false, "run as CGI script") - webf.BoolVar(&webArgs.dev, "dev", false, "run web client in developer mode [this flag is in development, use is unsupported]") webf.StringVar(&webArgs.prefix, "prefix", "", "URL prefix added to requests (for cgi or reverse proxies)") return webf })(), @@ -51,7 +50,6 @@ Tailscale, as opposed to a CLI or a native app. var webArgs struct { listen string cgi bool - dev bool prefix string } @@ -104,7 +102,6 @@ func runWeb(ctx context.Context, args []string) error { webServer, err := web.NewServer(web.ServerOpts{ Mode: cliServerMode, - DevMode: webArgs.dev, CGIMode: webArgs.cgi, PathPrefix: webArgs.prefix, LocalClient: &localClient, diff --git a/ipn/ipnlocal/web_client.go b/ipn/ipnlocal/web_client.go index 0b20a1cbc..4b18019f7 100644 --- a/ipn/ipnlocal/web_client.go +++ b/ipn/ipnlocal/web_client.go @@ -52,8 +52,7 @@ func (b *LocalBackend) WebClientInit() (err error) { b.logf("WebClientInit: initializing web ui") if b.webClient.server, err = web.NewServer(web.ServerOpts{ - Mode: web.ManageServerMode, - // TODO(sonia): allow passing back dev mode flag + Mode: web.ManageServerMode, LocalClient: b.webClient.lc, Logf: b.logf, }); err != nil { @@ -75,8 +74,8 @@ func (b *LocalBackend) WebClientShutdown() { b.mu.Unlock() // release lock before shutdown if server != nil { server.Shutdown() + b.logf("WebClientShutdown: shut down web ui") } - b.logf("WebClientShutdown: shut down web ui") } // handleWebClientConn serves web client requests. diff --git a/tsnet/example/web-client/web-client.go b/tsnet/example/web-client/web-client.go index c85dfc9d4..2f64f3dd9 100644 --- a/tsnet/example/web-client/web-client.go +++ b/tsnet/example/web-client/web-client.go @@ -14,8 +14,7 @@ import ( ) var ( - addr = flag.String("addr", "localhost:8060", "address of Tailscale web client") - devMode = flag.Bool("dev", false, "run web client in dev mode") + addr = flag.String("addr", "localhost:8060", "address of Tailscale web client") ) func main() { @@ -32,7 +31,6 @@ func main() { // Serve the Tailscale web client. ws, err := web.NewServer(web.ServerOpts{ Mode: web.LegacyServerMode, - DevMode: *devMode, LocalClient: lc, }) if err != nil {