server

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server provides the live preview HTTP server. It watches files with fsnotify and pushes reload notifications over WebSocket.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// Configuration
	Host      string // Listening host or IP.
	Port      int    // Listening port.
	WatchDir  string // Source directory to watch.
	OutputDir string // Output directory.
	AutoOpen  bool   // Whether to open the browser automatically.

	// AllowedHosts lists extra Host header names (port optional) the server
	// answers to, for example a reverse-proxy or tunnel host name. Loopback
	// names and the --host address are always allowed; see hostAllowed.
	AllowedHosts []string

	// BuildFunc is provided by the caller and rebuilds the project output.
	BuildFunc func() error
	// contains filtered or unexported fields
}

Server implements the live preview server.

func NewServer

func NewServer(host string, port int, watchDir, outputDir string, logger *slog.Logger) *Server

NewServer creates a preview server.

func (*Server) LastBuildError added in v0.8.0

func (s *Server) LastBuildError() string

LastBuildError returns the rebuild failure still in effect, or "" when the most recent build succeeded.

func (*Server) Listen

func (s *Server) Listen() (net.Listener, error)

Listen reserves the configured port and returns the listener.

func (*Server) ListenFrom

func (s *Server) ListenFrom(startPort int) (net.Listener, error)

ListenFrom reserves the first available port from startPort upward.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start runs the server until the context is canceled.

func (*Server) StartWithListener

func (s *Server) StartWithListener(ctx context.Context, ln net.Listener) error

StartWithListener runs the server using a pre-bound listener.

Jump to

Keyboard shortcuts

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