server

package
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 46 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server runs backd's server roles (API, worker, provisioning, the executor and egress bootstrap): settings, config loading and startup checks, the MongoDB client, and the dev-mode reloader.

Index

Constants

View Source
const EgressHelp = `Runs backd's egress role: the only way a function process reaches the
network. An HTTP forward/CONNECT proxy that resolves every target itself
and refuses loopback, private, link-local (metadata), CGNAT, multicast and
unspecified addresses; each function process authenticates with a token
scoped to its own invocation (minted by ` + "`backd-server executor`" + `), so the proxy
enforces that invocation's allowlist too.

Environment:
  BACKD_EGRESS_KEY      required: the secret shared with the executor
                        (32+ characters), verifies each process's token
  EGRESS_ADDR           listen address (default :3128)
  EGRESS_ALLOW_PRIVATE  comma-separated host:port exceptions to the
                        private-address block (backd's callback listener)
  LOG_LEVEL             debug, info, warn or error (default info)

It must be the executor network's only route out; MongoDB and backd's
other endpoints must stay unreachable from it (network placement, not
something this process enforces).
`
View Source
const ExecutorHelp = `Runs server-side functions for backd: each call in its own Deno process,
with only the function's permissions and limits. Needs Deno ` + registry.DenoVersion + `
(the backd-executor image has it), never CONFIG_DIR or MongoDB.

Environment:
  BACKD_EXECUTOR_TOKEN     required: the secret shared with backd (32+ characters)
  EXECUTOR_ADDR            listen address (default :9100)
  EXECUTOR_DIR             writable directory for the bundle cache
                           (default: a backd-executor directory in the temp dir)
  EXECUTOR_MAX_PROCESSES   functions running at once (default 64)
  EXECUTOR_PROXY           backd-server egress's base URL (e.g. http://backd-egress:3128);
                           without it, function processes get no outbound
                           network beyond --allow-net on this host
  BACKD_EGRESS_KEY         required with EXECUTOR_PROXY (32+ characters): signs
                           each invocation's egress credentials
  DENO                     the Deno binary (default deno on the PATH)
  LOG_LEVEL                debug, info, warn or error (default info)

It must only be reachable by backd, and reach only backd's internal
listener and backd-server egress.
`

Variables

This section is empty.

Functions

func Provision

func Provision(ctx context.Context, a *App) error

func Run

func Run(ctx context.Context, role string, getenv func(string) string, logOut io.Writer, o Options) error

Run runs a server role (serve, worker or provision) with its flags. Outside dev mode, or for provision, any startup error is final. In dev mode (BACKD_DEV), serve and worker don't exit on what the developer edits (see runDev).

func Serve

func Serve(ctx context.Context, a *App) error

func ServeEgress

func ServeEgress(getenv func(string) string, stderr io.Writer) error

func ServeExecutor

func ServeExecutor(getenv func(string) string, stderr io.Writer) error

func Worker

func Worker(ctx context.Context, a *App) error

Worker runs `backd Worker`: the same async-job loop as `serve --with-Worker`, in its own process with no HTTP listener.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App holds what every command needs: settings, logger, registry, MongoDB client.

func NewApp

func NewApp(cfg settings.Settings, log *slog.Logger, reg *registry.Registry, client *mongo.Client, fingerprint string) *App

NewApp is an app on a config that is already loaded and a connected client, for the tools that work on the database directly without the startup checks (Setup does them).

func Setup

func Setup(ctx context.Context, getenv func(string) string, logOut io.Writer) (*App, error)

Setup loads the settings and the config and connects to MongoDB: what every role and direct tool needs. Any error is final (Run is the dev-mode start that waits instead).

func (*App) Client

func (a *App) Client() *mongo.Client

Client is the app's MongoDB client.

func (*App) Close

func (a *App) Close()

func (*App) Handler

func (a *App) Handler() http.Handler

Handler builds the HTTP Handler that serve runs.

func (*App) HandlerConfig

func (a *App) HandlerConfig() httpapi.Config

func (*App) InternalHandler

func (a *App) InternalHandler() http.Handler

InternalHandler serves the internal listener (functions only).

func (*App) Log

func (a *App) Log() *slog.Logger

Log is the app's logger.

func (*App) OpenEvents

func (a *App) OpenEvents() func()

OpenEvents prepares this instance's realtime consumer when BACKD_EVENTS allows it. Nothing is read until a subscriber arrives, so it costs nothing on an instance without any. It returns the function that closes it.

func (*App) Provisioner

func (a *App) Provisioner() *mongodb.Provisioner

func (*App) RealmUsers

func (a *App) RealmUsers() func(string) *auth.Users

RealmUsers returns the user service of every auth-enabled realm, built on first use. They share one Hasher, so the hashing concurrency cap applies per process.

func (*App) Registry

func (a *App) Registry() *registry.Registry

Registry is the loaded config.

func (*App) Rescan

Rescan reads a collection's stored documents again and queues the trigger jobs their changes would have queued (`backd-server triggers rescan`).

func (*App) SetOptions

func (a *App) SetOptions(o Options)

SetOptions applies the role flags before the role runs.

func (*App) Settings

func (a *App) Settings() *settings.Settings

Settings are the app's settings. Tests change them (the executor and callback addresses of servers they start) before the app serves.

func (*App) UsersOf

func (a *App) UsersOf(ctx context.Context, realm string) (*auth.Users, error)

UsersOf returns the user service of an auth-enabled, provisioned realm.

type Options

type Options struct {
	// WithWorker runs the worker role in this process too (serve --with-worker).
	WithWorker bool
	// DisablePreImages and Yes are provision's --disable-preimages and --yes.
	DisablePreImages, Yes bool
}

Options are the flags of the role commands.

Jump to

Keyboard shortcuts

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