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 <sonia@tailscale.com>
pull/10109/head
Sonia Appasamy 7 months ago committed by Sonia Appasamy
parent f0bc95a066
commit 0ecfc1d5c3

@ -43,6 +43,9 @@ type Server struct {
lc *tailscale.LocalClient lc *tailscale.LocalClient
timeNow func() time.Time 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 devMode bool
cgiMode bool cgiMode bool
pathPrefix string pathPrefix string
@ -100,11 +103,6 @@ type ServerOpts struct {
// Mode specifies the mode of web client being constructed. // Mode specifies the mode of web client being constructed.
Mode ServerMode 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 indicates if the server is running as a CGI script.
CGIMode bool CGIMode bool
@ -143,7 +141,7 @@ func NewServer(opts ServerOpts) (s *Server, err error) {
s = &Server{ s = &Server{
mode: opts.Mode, mode: opts.Mode,
logf: opts.Logf, logf: opts.Logf,
devMode: opts.DevMode, devMode: envknob.Bool("TS_DEBUG_WEB_CLIENT_DEV"),
lc: opts.LocalClient, lc: opts.LocalClient,
cgiMode: opts.CGIMode, cgiMode: opts.CGIMode,
pathPrefix: opts.PathPrefix, pathPrefix: opts.PathPrefix,
@ -155,7 +153,7 @@ func NewServer(opts ServerOpts) (s *Server, err error) {
if s.logf == nil { if s.logf == nil {
s.logf = log.Printf 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 var metric string // clientmetric to report on startup

@ -41,7 +41,6 @@ Tailscale, as opposed to a CLI or a native app.
webf := newFlagSet("web") webf := newFlagSet("web")
webf.StringVar(&webArgs.listen, "listen", "localhost:8088", "listen address; use port 0 for automatic") 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.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)") webf.StringVar(&webArgs.prefix, "prefix", "", "URL prefix added to requests (for cgi or reverse proxies)")
return webf return webf
})(), })(),
@ -51,7 +50,6 @@ Tailscale, as opposed to a CLI or a native app.
var webArgs struct { var webArgs struct {
listen string listen string
cgi bool cgi bool
dev bool
prefix string prefix string
} }
@ -104,7 +102,6 @@ func runWeb(ctx context.Context, args []string) error {
webServer, err := web.NewServer(web.ServerOpts{ webServer, err := web.NewServer(web.ServerOpts{
Mode: cliServerMode, Mode: cliServerMode,
DevMode: webArgs.dev,
CGIMode: webArgs.cgi, CGIMode: webArgs.cgi,
PathPrefix: webArgs.prefix, PathPrefix: webArgs.prefix,
LocalClient: &localClient, LocalClient: &localClient,

@ -52,8 +52,7 @@ func (b *LocalBackend) WebClientInit() (err error) {
b.logf("WebClientInit: initializing web ui") b.logf("WebClientInit: initializing web ui")
if b.webClient.server, err = web.NewServer(web.ServerOpts{ if b.webClient.server, err = web.NewServer(web.ServerOpts{
Mode: web.ManageServerMode, Mode: web.ManageServerMode,
// TODO(sonia): allow passing back dev mode flag
LocalClient: b.webClient.lc, LocalClient: b.webClient.lc,
Logf: b.logf, Logf: b.logf,
}); err != nil { }); err != nil {
@ -75,8 +74,8 @@ func (b *LocalBackend) WebClientShutdown() {
b.mu.Unlock() // release lock before shutdown b.mu.Unlock() // release lock before shutdown
if server != nil { if server != nil {
server.Shutdown() server.Shutdown()
b.logf("WebClientShutdown: shut down web ui")
} }
b.logf("WebClientShutdown: shut down web ui")
} }
// handleWebClientConn serves web client requests. // handleWebClientConn serves web client requests.

@ -14,8 +14,7 @@ import (
) )
var ( var (
addr = flag.String("addr", "localhost:8060", "address of Tailscale web client") addr = flag.String("addr", "localhost:8060", "address of Tailscale web client")
devMode = flag.Bool("dev", false, "run web client in dev mode")
) )
func main() { func main() {
@ -32,7 +31,6 @@ func main() {
// Serve the Tailscale web client. // Serve the Tailscale web client.
ws, err := web.NewServer(web.ServerOpts{ ws, err := web.NewServer(web.ServerOpts{
Mode: web.LegacyServerMode, Mode: web.LegacyServerMode,
DevMode: *devMode,
LocalClient: lc, LocalClient: lc,
}) })
if err != nil { if err != nil {

Loading…
Cancel
Save