devserver

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: AGPL-3.0 Imports: 23 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 devserver runs a project's own development server and exposes it to the console through a reverse proxy that speaks the whole protocol the app expects: HTTP methods and bodies, cookies, redirects, streaming and WebSockets. It is the live-preview counterpart to the artifact preview origin: a packed archive shows what a task produced, while this shows what the project's dev server is serving right now, HMR included.

A project opts in with .panda/dev.json in its work directory:

{
  "command": "npm run dev",
  "url": "http://127.0.0.1:5173",
  "auto_start": true,
  "ready_timeout_s": 60
}

The target must be loopback: the command runs on this node, and a public or LAN address here would turn the proxy into a general-purpose fetcher. The proxy itself listens on a fresh port per project, so root-absolute asset URLs and the dev server's own WebSocket work without rewriting: the port is the origin, and a per-start token is exchanged for an HttpOnly cookie before the app is served.

Index

Constants

View Source
const ConfigFile = ".panda/dev.json"

ConfigFile is the project-level opt-in, relative to the project work dir.

View Source
const DefaultReadyTimeout = 60

DefaultReadyTimeout is how long a start waits for the dev server to answer.

View Source
const MaxReadyTimeout = 300

MaxReadyTimeout bounds a config's own patience.

Variables

View Source
var ErrNotConfigured = errors.New("devserver: project has no " + ConfigFile)

ErrNotConfigured is returned by LoadConfig when the project has no .panda/dev.json. It is not a failure: most projects have no dev server.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Command is run through the platform shell in the project work dir.
	Command string `json:"command"`
	// URL is the loopback address the dev server serves. The reverse proxy
	// targets exactly this; the command must bring the server up there.
	URL string `json:"url"`
	// Cwd, when set, is where the command runs. Relative paths stay under the
	// work dir.
	Cwd string `json:"cwd,omitempty"`
	// AutoStart opens the preview after a task settles without asking.
	AutoStart bool `json:"auto_start"`
	// ReadyTimeoutS bounds the readiness wait; zero uses the default.
	ReadyTimeoutS int `json:"ready_timeout_s,omitempty"`
}

Config is one project's dev-server declaration.

func LoadConfig

func LoadConfig(workDir string) (Config, string, error)

LoadConfig reads and validates a project's dev declaration. The second return is the absolute working directory the command runs in.

type Manager

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

Manager owns every project's dev server, its listener and its status.

func Start

func Start(o Options) *Manager

Start creates a Manager. It starts no listeners and no processes: those appear when a project's dev server is started.

func (*Manager) Close

func (m *Manager) Close()

Close stops every dev server and listener.

func (*Manager) Origins

func (m *Manager) Origins(requestHost string) []string

Origins lists the frameable origins of ready dev servers as this request host can reach them. The console's CSP admits exactly these, because the listener ports are ephemeral and a wildcard would admit more than previews.

func (*Manager) StartProject

func (m *Manager) StartProject(project string) (Status, error)

StartProject starts a project's dev server if it is not already up. It returns as soon as the process and listener exist; the readiness probe runs in the background and lands in Status.

func (*Manager) Status

func (m *Manager) Status(project, requestHost string) Status

Status reports one project without starting anything. requestHost is the host the console request arrived on, used to build a reachable preview URL.

func (*Manager) StopProject

func (m *Manager) StopProject(project string) Status

StopProject stops a project's dev server. It is idempotent.

type Options

type Options struct {
	// Host is the interface the per-project listeners bind. It follows the
	// console: loopback for a loopback console, all interfaces when the console
	// was opened to the LAN. Empty means loopback.
	Host string
	// Resolve names the work dir of a project. nil resolves nothing.
	Resolve func(project string) (workDir string, ok bool)
	Logger  *slog.Logger
	// ShellCommand overrides the platform shell for tests.
	ShellCommand func(command string) (string, []string)
}

Options configure a Manager.

type State

type State string

State is where one project's dev server stands.

const (
	StateStopped  State = "stopped"
	StateStarting State = "starting"
	StateReady    State = "ready"
	StateFailed   State = "failed"
)

type Status

type Status struct {
	Project       string `json:"project"`
	Configured    bool   `json:"configured"`
	State         State  `json:"state"`
	Command       string `json:"command,omitempty"`
	Target        string `json:"target,omitempty"`
	URL           string `json:"url,omitempty"`
	AutoStart     bool   `json:"auto_start,omitempty"`
	ReadyTimeoutS int    `json:"ready_timeout_s,omitempty"`
	Error         string `json:"error,omitempty"`
	Log           string `json:"log,omitempty"`
	Since         int64  `json:"since,omitempty"`
}

Status is the console's whole view of one project's dev server. URL is built per request host: the listener follows the console's reach, so the address a LAN browser must use is not the address a loopback browser sees.

Jump to

Keyboard shortcuts

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