Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAdminDevProxy ¶
NewAdminDevProxy creates an http.Handler that proxies non-API /admin/ requests to the Vite dev server during development. API requests (/admin/api/) are served directly by huan, preserving the full API behavior.
Usage:
./huan serve --adminDev http://localhost:5173 cd web/admin && npm run dev # separate terminal
Types ¶
type LiveReloadHub ¶
type LiveReloadHub struct {
// contains filtered or unexported fields
}
LiveReloadHub manages WebSocket connections from browser clients running livereload.js. It broadcasts reload and alert messages to all clients.
Each client has its own writer goroutine that serializes writes — required because coder/websocket forbids concurrent calls to Conn.Write per conn. Broadcasts are fan-out to per-client send channels, so slow clients don't block other clients or the broadcaster.
func NewHub ¶
func NewHub() *LiveReloadHub
func (*LiveReloadHub) AcceptHTTP ¶
func (h *LiveReloadHub) AcceptHTTP(w http.ResponseWriter, r *http.Request)
AcceptHTTP upgrades an HTTP request to a WebSocket and hands it to the hub. Convenience for wiring into a stdlib mux.
func (*LiveReloadHub) BroadcastAlert ¶
func (h *LiveReloadHub) BroadcastAlert(message string)
BroadcastAlert shows an alert popup in connected browsers (used for build errors).
func (*LiveReloadHub) BroadcastReload ¶
func (h *LiveReloadHub) BroadcastReload()
BroadcastReload notifies all clients to refresh the page.
func (*LiveReloadHub) ClientCount ¶
func (h *LiveReloadHub) ClientCount() int
ClientCount returns the current number of connected clients (useful for tests/logging).
func (*LiveReloadHub) HandleConn ¶
func (h *LiveReloadHub) HandleConn(ctx context.Context, c *websocket.Conn)
HandleConn runs the WebSocket lifecycle for one client: starts a writer goroutine, sends the hello message, then runs the read loop until the client disconnects or ctx is cancelled. Blocks until disconnect.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves the built site over HTTP.
func New ¶
func New(opts ServerOptions) *Server
type ServerOptions ¶
type ServerOptions struct {
OutputDir string
Bind string
Port string // ":0" or "0" makes the OS pick a free port
Hub *LiveReloadHub // optional; if nil, /livereload route returns 404
AdminHandler http.Handler // optional; if non-nil, mounted at /admin/
Logf func(format string, args ...any)
}
ServerOptions configures a Server.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher recursively watches SourceDir for changes and invokes OnChange after a debounce delay.
func NewWatcher ¶
func NewWatcher(opts WatcherOptions) (*Watcher, error)