preview

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package preview implements `puzzle preview`: a local server for an ALREADY BUILT dist/, behaving the way the host that will serve it behaves. There is no watcher, no rebuild, no live-reload injection and no dev.proxy — the output is served exactly as it sits on disk, because the point of the command is to check the artifact rather than the source.

What "the way a host behaves" means is decided by the resolved output mode from puzzle.config.js (D81), and that resolution lives in internal/serve so `puzzle dev` answers static URLs identically:

  • SPA: history-API fallback — anything that is not a file is index.html.
  • hybrid: the route's prerendered page when one was written, index.html otherwise (the router owns the rest).
  • static: clean URLs and a real 404 on a miss. No index.html fallback: a static host has no router to fall back to, and a preview that quietly served the home page for a missing route would hide exactly the bug this command exists to catch.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(dist, mode string) http.Handler

Handler serves dist per mode. Exported so tests (and any future caller) can drive it through httptest without binding a port.

func Serve

func Serve(root string, opts Options) error

Serve serves root/dist for the app rooted at root and blocks until SIGINT/SIGTERM.

Types

type Options

type Options struct {
	// Port is the TCP port to listen on. A busy port is not fatal: the D90 scan
	// takes the next free one unless StrictPort is set.
	Port int
	// StrictPort binds Port or fails, for the same reasons `puzzle dev` has it —
	// container mappings and redirect URIs pin a number on purpose.
	StrictPort bool
	// OnReady runs after the ready banner is printed (test/CLI hook).
	OnReady func()
}

Options configure Serve.

Jump to

Keyboard shortcuts

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