Overview
TheServer type is the main entry point for pb-ext applications. It wraps a PocketBase instance and adds production-ready features including analytics, job management, health monitoring, and structured logging.
Type Definition
core/server/server.go:18
Constructor
New
Creates a new Server instance with optional configuration.Variadic functional options for configuring the server. See Options for available options.
*Server - A configured server instance ready to start.
Example:
core/server/server.go:43
The constructor initializes the server but does not start it. Call
Start() to begin serving requests.Methods
Start
Initializes and starts the server, including all subsystems (analytics, jobs, health monitoring).error - Returns an error if the server fails to start, nil otherwise.
Lifecycle:
-
Bootstrap Phase (
OnBootstrap):- Initializes job management system
- Registers internal system jobs
- Sets up job handlers
-
Serve Phase (
OnServe):- Registers request tracking middleware
- Initializes analytics system
- Registers job API routes
- Serves static files from
pb_public/ - Starts the HTTP server
core/server/server.go:80
App
Returns the underlying PocketBase instance for direct access to PocketBase APIs.*pocketbase.PocketBase - The wrapped PocketBase instance.
Example:
core/server/server.go:260
Stats
Returns the current server statistics.*ServerStats - Server statistics including request counts, active connections, and timing data.
Example:
core/server/server.go:265
ServerStats Type
Tracks real-time server metrics using atomic operations for thread-safe access.core/server/server.go:28
Fields
Server startup timestamp (not atomic, set once at initialization).
Total number of HTTP requests processed. Excludes
/service-worker.js, /favicon.ico, and /manifest.json.Access: stats.TotalRequests.Load()Current number of active HTTP connections being processed.Access:
stats.ActiveConnections.Load()Unix timestamp (seconds) of the last processed request.Access:
time.Unix(stats.LastRequestTime.Load(), 0)Total number of requests that returned errors.Access:
stats.TotalErrors.Load()Rolling average request processing time in nanoseconds.Access:
time.Duration(stats.AverageRequestTime.Load())All numeric fields use atomic types for thread-safe concurrent access. Use the
.Load() method to read values.Complete Example
See Also
- Options - Server configuration options
- Jobs - Cron job management
- Analytics - Request analytics and visitor tracking
- Health Dashboard - Built-in monitoring dashboard