web

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package web serves a Nimbus Native app's pages to browsers: the same components the phone apps run, rendered on the server.

A request for a page runs the app's UI on the server until its data has loaded and answers with plain HTML, with the page's title and meta tags, so search engines and link previews see real content. A small script (host.js, 36 KB, 11 KB gzipped) then takes over that HTML: taps and typing go to the page's UI session on the server, and the changes it renders come back as DOM updates. Layout is the browser's own CSS flexbox.

Mount it on a Nimbus app as the fallback for everything the API doesn't serve:

site := web.Handler(web.Options{SiteName: "Shop", Layout: app.WebLayout, Home: "/orders"})
app.Router.Fallback(func(c *nhttp.Context) error { site.ServeHTTP(c.Response, c.Request); return nil })

Pages come from the app's router table (router.Register); a page's Head() method gives its title, description and preview image.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(o Options) http.Handler

Handler serves pages, the host script and the session endpoints.

Types

type Options

type Options struct {
	// SiteName follows page titles ("Order #42 · Shop").
	SiteName string
	// Layout wraps every page: the web's shell (a header, navigation),
	// where the phones have tabs and stacks. Nil shows pages alone.
	Layout func(path string, page ui.Component) ui.Component
	// Home is where "/" redirects when no page has that path.
	Home string
	// BaseURL is the site's public address ("https://shop.example"), for
	// canonical links and the sitemap; by default the request's host.
	BaseURL string
	// Lang is the page language (default "en").
	Lang string
	// SettleTimeout bounds how long a page waits for its data before the
	// HTML goes out anyway (default 3s).
	SettleTimeout time.Duration
	// FontDir holds the app's bundled fonts (<family>.ttf or .otf), served
	// to browsers for Style.FontFamily. New projects use the Android app's
	// font folder.
	FontDir string
}

Options configure the site.

Jump to

Keyboard shortcuts

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