frontend

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 38 Imported by: 0

Documentation

Overview

Package frontend serves the HTML pages (Go templates + htmx). It has no database: everything else it asks of the backend through the internal API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Frontend

type Frontend struct {

	// Version is shown on the admin page.
	Version string
	// contains filtered or unexported fields
}

Frontend is the half of the application that renders pages. It has no database and no keys: it asks the backend for everything through api, the internal API over HTTP, and acts only on the few administrator settings the backend hands it (frontendSettings). The Backend is another type, so nothing here can reach its fields.

func NewFrontend

func NewFrontend(api *apiclient.Client) (*Frontend, error)

NewFrontend builds a frontend that talks to the backend through api and parses the embedded templates. Call RefreshConfig before serving, and StartConfigPoll to follow changes.

func (*Frontend) Close

func (s *Frontend) Close()

Close cancels the background jobs and waits for them to stop, and stops the HTTPS and HTTP/3 servers. Call it after the HTTP server has been shut down.

func (*Frontend) DisableLimits

func (s *Frontend) DisableLimits()

DisableLimits turns off the request limits of the frontend. The combined process uses it: it has a load budget of its own, shared with the API.

func (*Frontend) Handler

func (s *Frontend) Handler() http.Handler

Handler returns the root HTTP handler.

func (*Frontend) RefreshConfig

func (s *Frontend) RefreshConfig(ctx context.Context) error

RefreshConfig fetches the settings from the backend and puts them in force if they changed.

func (*Frontend) SetAPIHandler

func (s *Frontend) SetAPIHandler(h http.Handler)

SetAPIHandler serves /api/ with h, the public API of a backend in the same process.

func (*Frontend) SetAPIUpstream

func (s *Frontend) SetAPIUpstream(u *url.URL)

SetAPIUpstream makes the frontend pass /api/ on to the backend's public listener, for setups with one public address and no reverse proxy that routes by path. The backend must list this process among its trusted proxies to see visitors' addresses.

func (*Frontend) StartConfigPoll

func (s *Frontend) StartConfigPoll()

StartConfigPoll follows changes to the settings until Close. A backend that is down is not an error here: the frontend keeps the last good settings.

func (*Frontend) StartListeners

func (s *Frontend) StartListeners(handler http.Handler)

StartListeners starts the HTTPS and HTTP/3 servers when the settings ask for them, with handler as their handler (the one the plain server uses). It is called again by reloadSettings whenever a setting changes, which starts, moves or stops them without a restart.

func (*Frontend) WaitForBackend

func (s *Frontend) WaitForBackend(ctx context.Context, timeout time.Duration) error

WaitForBackend fetches the first configuration, retrying until the backend answers or timeout passes, so a frontend started together with its backend does not give up too early.

func (*Frontend) WrapListener

func (s *Frontend) WrapListener(ln net.Listener) net.Listener

WrapListener makes ln understand the PROXY protocol according to the current settings. Wrap the listener once at start; it costs nothing while the setting is off.

It also remembers the address, which the HTTPS and HTTP/3 servers (tlsserve.go) take their interface from.

Jump to

Keyboard shortcuts

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