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 ¶
const ConfigFile = ".panda/dev.json"
ConfigFile is the project-level opt-in, relative to the project work dir.
const DefaultReadyTimeout = 60
DefaultReadyTimeout is how long a start waits for the dev server to answer.
const MaxReadyTimeout = 300
MaxReadyTimeout bounds a config's own patience.
Variables ¶
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.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns every project's dev server, its listener and its status.
func Start ¶
Start creates a Manager. It starts no listeners and no processes: those appear when a project's dev server is started.
func (*Manager) Origins ¶
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 ¶
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 ¶
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 ¶
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 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.