server

package
v0.13.4 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package server provides the HTTP server, routing, and TLS configuration for the DMCN web client backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ListenAddr string
	Domain     string
	TLSCert    string
	TLSKey     string
	DevMode    bool
	DataDir    string
}

Config holds HTTP server configuration.

type FrontendConfig

type FrontendConfig struct {
	Version       string
	DefaultDomain string
	// Domains is the comma-separated set of domains the register UI offers in its
	// domain picker (env.DOMAINS). The authoritative registrability check lives on
	// the account service (fleet permits + DAR policy) — this is presentation only.
	Domains        string
	DevMode        bool
	PollIntervalMs int
	// Domain is the HOSTNAME this client is served on — used for the CORS origin and the TLS
	// certificate. It is NOT necessarily the DMCN domain: addresses may be user@example.com while
	// the client is served from mail.example.com. FrontendConfig.DefaultDomain carries the DMCN
	// domain, which is what addresses are formed from.
	//
	// DomainRootPub is this domain's root Ed25519 public key, base64. Public by construction —
	// it is what the domain's _dmcn DNS fingerprint commits to. The SPA uses it to verify a
	// bridge's credential itself, so the server cannot influence whether bridged mail looks
	// trustworthy.
	DomainRootPub string
	// PetitionMode marks a live self-hosted domain whose root key is offline: nobody can
	// self-register, but anyone can PETITION for a mailbox and have an admin assign one. The
	// register page becomes the petition flow rather than a closed screen.
	PetitionMode bool
}

FrontendConfig holds non-secret, deploy-specific values rendered into the SPA shell (index.html) as the global `env` object, so one embedded build can be configured per deploy without rebuilding the frontend.

type Server

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

Server wraps the standard library HTTP server with DMCN routing.

func New

func New(cfg Config, logger logr.Logger) *Server

New creates a Server with the given configuration and logger.

func (*Server) RegisterAPI

func (s *Server) RegisterAPI(
	auth *api.AuthHandler,
	msg *api.MessageHandler,
	ident *api.IdentityHandler,
	mailbox *api.MailboxHandler,
	reg *api.RegisterHandler,
	pet *api.PetitionHandler,
	authMiddleware func(http.HandlerFunc) http.HandlerFunc,
	frontendFS fs.FS,
	frontendConfig FrontendConfig,
)

RegisterAPI wires API handlers and the embedded frontend into the server's multiplexer. The authMiddleware function wraps handlers that require an authenticated session.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server.

func (*Server) Start

func (s *Server) Start(certFile, keyFile string) error

Start begins listening. If certFile and keyFile are non-empty it starts a TLS server; otherwise it starts a plain HTTP server.

func (*Server) StartAutocert

func (s *Server) StartAutocert(hosts []string, cacheDir string) error

StartAutocert begins listening with automatic TLS certificates from Let's Encrypt via the ACME protocol, for every name in hosts.

More than one, because the hostname serving the webmail need not be the DMCN domain: addresses can be user@example.com while the client lives at mail.example.com, exactly as ordinary email separates the two. A name that never arrives over SNI costs nothing, so both are whitelisted and whichever the operator actually points at this node works.

Jump to

Keyboard shortcuts

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