The httpd subpackage provides a high-level, "batteries-included" HTTP server implementation that implements the github.com/tinywasm/router contract.
The development mode's internalStrategy (in-memory server) consumes the httpd.NewRouter adapter to provide consistent routing behavior between development and production.
When a project lacks a custom web/server.go or switches to external mode without customization, the generator.go uses templates/server_basic.md to create a entry point. This entry point is a thin wrapper around httpd.New(), avoiding boilerplate duplication.
adapter.go: Implementation ofrouter.Router,router.Context, etc., mapping them tonet/http.middleware.go: Built-inGzipandNoCachemiddlewares.static.go: Static file serving fromPublicDir.enforce.go: RBAC enforcement based onRequiresmetadata.tls.go/devcert.go: Support for AutoCert (Let's Encrypt), custom Cert/Key, andDevTLS(self-signed with local truststore installation).routes_endpoint.go: Optional JSON endpoint at/_routeslisting all registered routes.httpd.go: CoreServerorchestrator.
- Simple Entry Point:
httpd.New(config).Mount(modules).ListenAndServe()is the only way to start the server. - Standard Library Based: Uses
net/httpinternally but doesn't expose it in the public API. - Fails Fast: Validates configuration (like TLS modes or RBAC requirements) at startup rather than at runtime.
The server follows a secure-by-default model where routes are private unless explicitly marked as Public(). However, for a smooth development experience:
- Static Assets: Files served from
PublicDir(e.g., WASM binaries, JS, CSS) are always public. They bypass the RBAC middleware. - Root Path (
/) in Development: The internal strategy registers a default public route for/that servesPublicDir/index.htmlor a diagnostic message. This ensures that the frontend application is accessible immediately without manual RBAC configuration.