server

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPortAvailable

func CheckPortAvailable(port int) bool

func EnsureFrontendDevServer

func EnsureFrontendDevServer(ctx context.Context, routePrefix string) (int, chan struct{}, error)

EnsureFrontendDevServer starts `bun run dev` for the React app on an auto-selected free port (starting at 5173) and blocks until the port is reachable. It returns the chosen port along with a channel that closes once the sub-process has fully terminated after ctx is cancelled.

Selecting a free port dynamically means multiple projects can run in --dev mode in parallel; it also avoids accidentally proxying to another project's vite instance that happens to own 5173.

func FindAvailablePort

func FindAvailablePort(startPort int, maxAttempts int) (int, error)

FindAvailablePort finds a port starting from startPort

func FormatTemplateHtml

func FormatTemplateHtml(opts FormatOptions) (string, error)

FormatTemplateHtml formats the template HTML with the given options

func Init

func Init(fs embed.FS, tmpl string)

func JoinRoutePrefix

func JoinRoutePrefix(routePrefix string, requestPath string) string

func NormalizeRoutePrefix

func NormalizeRoutePrefix(prefix string) string

NormalizeRoutePrefix converts values like "my-app" and "/my-app/" to "/my-app". Empty and "/" mean the app is mounted at the host root.

func ProxyDev

func ProxyDev(mux *http.ServeMux, vitePort int, routePrefix string) error

func RegisterAPI

func RegisterAPI(mux *http.ServeMux) error

func Serve

func Serve(port int, dev bool, routePrefix string) error

func ServeComponent

func ServeComponent(port int, opts ServeOptions) error

func SetDataDir

func SetDataDir(dataDir string)

func Static

func Static(mux *http.ServeMux, opts StaticOptions) error

Types

type FormatOptions

type FormatOptions struct {
	Title          string // __TITLE__ placeholder
	Render         string // __RENDER__ placeholder (default: "renderComponent")
	Component      string // __COMPONENT__ placeholder (mandatory)
	ComponentProps string // __COMPONENT_PROPS__ placeholder (default: "{}")
}

FormatOptions contains the options for formatting the template HTML

type ServeOptions

type ServeOptions struct {
	Static      StaticOptions
	Route       func(mux *http.ServeMux) error // Optional custom route registration
	Dev         bool
	RoutePrefix string
}

type StaticOptions

type StaticOptions struct {
	IndexHtml   string // Custom HTML content to serve instead of embedded index.html
	RoutePrefix string
}

Jump to

Keyboard shortcuts

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