Documentation
¶
Overview ¶
Package web is the HTTP adapter: a localhost notes viewer (`nt web`). It is a read adapter over the same domain (note/links/mutate) the CLI, TUI, and MCP server use — so it shows exactly what they store. It is deliberately structured to make editing a future additive change: state lives on the Server struct, notes are addressed by stable id, and the render path is one reusable function.
Index ¶
Constants ¶
const DefaultPort = 4321
DefaultPort is the stable port `nt web` binds by default, so the URL stays the same across runs (bookmarkable). If it's already in use, Serve falls back to a free port rather than failing — the address only changes on an actual conflict.
Variables ¶
This section is empty.
Functions ¶
func Serve ¶
Serve opens the store and serves the SPA on addr (e.g. "127.0.0.1:4321"). If the requested port is taken, it falls back to a free one (so the port is stable run-to-run but a conflict doesn't crash the command). onReady, if non-nil, is called with the final base URL once the listener is bound — used by the detached server (`nt web --detach`) to record its real address in the PID file even when the port fell back.
Types ¶
type Backlink ¶
type Backlink struct {
Title string `json:"title"` // note title, or "" for a task source
URL string `json:"url"` // /n/<id> for a note source; "" for a task
Text string `json:"text"` // the matching line (shown for task sources)
IsNote bool `json:"isNote"`
}
Backlink is one "Linked from" entry for the note page.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server holds the shared state for the viewer. Writes (notes and tasks) are always enabled; every write route is guarded by the per-process CSRF token.
func (*Server) Handler ¶ added in v0.4.0
Handler returns the viewer's HTTP handler so another host can serve the UI without nt binding a TCP port — e.g. a Wails desktop shell wiring it into assetserver.Options.Handler. This is the seam that lets the exact same server-rendered UI run as a native app. Call StartWatch first if you want live-reload. Editing is always enabled (CSRF-guarded).
func (*Server) SetSPA ¶ added in v0.4.0
SetSPA is a no-op retained for embedder compatibility; the SPA is always served.
func (*Server) StartWatch ¶ added in v0.4.0
func (s *Server) StartWatch()
StartWatch begins watching the store and pushing SSE live-reload events. Serve calls this itself; embedders call it when they want live-reload.