Help us shape the future of Go! Take the 2026 Go Developer Survey

web

package
v1.104.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: BSD-3-Clause Imports: 50 Imported by: 8

Documentation

Overview

Package web provides the Tailscale client for web.

Index

Constants

View Source
const ListenPort = 5252

ListenPort is the static port used for the web client when run inside tailscaled. (5252 are the numbers above the letters "TSTS" on a qwerty keyboard.)

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the backend server for a Tailscale web client.

func NewServer

func NewServer(opts ServerOpts) (s *Server, err error)

NewServer constructs a new Tailscale web client server. If err is empty, s is always non-nil. ctx is only required to live the duration of the NewServer call, and not the lifespan of the web server.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP processes all requests for the Tailscale web client.

func (*Server) Shutdown added in v1.54.0

func (s *Server) Shutdown()

type ServerMode added in v1.54.0

type ServerMode string

ServerMode specifies the mode of a running web.Server.

const (
	// LoginServerMode serves a read-only login client for logging a
	// node into a tailnet, and viewing a read-only interface of the
	// node's current Tailscale settings.
	//
	// In this mode, API calls are authenticated via platform auth.
	LoginServerMode ServerMode = "login"

	// ReadOnlyServerMode is identical to LoginServerMode,
	// but does not present a login button to switch to manage mode,
	// even if the management client is running and reachable.
	//
	// This is designed for platforms where the device is configured by other means,
	// such as Home Assistant's declarative YAML configuration.
	ReadOnlyServerMode ServerMode = "readonly"

	// ManageServerMode serves a management client for editing tailscale
	// settings of a node.
	//
	// This mode restricts the app to only being assessible over Tailscale,
	// and API calls are authenticated via browser sessions associated with
	// the source's Tailscale identity. If the source browser does not have
	// a valid session, a read-only version of the app is displayed.
	ManageServerMode ServerMode = "manage"
)

type ServerOpts added in v1.50.0

type ServerOpts struct {
	// Mode specifies the mode of web client being constructed.
	Mode ServerMode

	// CGIMode indicates if the server is running as a CGI script.
	CGIMode bool

	// PathPrefix is the URL prefix added to requests by CGI or reverse proxy.
	PathPrefix string

	// LocalClient is the local.Client to use for this web server.
	// If nil, a new one will be created.
	LocalClient *local.Client

	// TimeNow optionally provides a time function.
	// time.Now is used as default.
	TimeNow func() time.Time

	// Logf optionally provides a logger function.
	// If nil, log.Printf is used as default.
	Logf logger.Logf

	// PolicyClient, if non-nil, will be used to fetch policy settings.
	// If nil, the default policy client will be used.
	PolicyClient policyclient.Client

	// NewAuthURL should be provided as a function that generates
	// a new tailcfg.WebClientAuthResponse.
	// This field is required for ManageServerMode mode.
	NewAuthURL func(ctx context.Context, src tailcfg.NodeID) (*tailcfg.WebClientAuthResponse, error)
	// WaitAuthURL should be provided as a function that blocks until
	// the associated tailcfg.WebClientAuthResponse has been marked
	// as completed.
	// This field is required for ManageServerMode mode.
	WaitAuthURL func(ctx context.Context, id string, src tailcfg.NodeID) (*tailcfg.WebClientAuthResponse, error)

	// OriginOverride specifies the origin that the web UI will be accessible from if hosted behind a reverse proxy or CGI.
	OriginOverride string
}

ServerOpts contains options for constructing a new Server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL