Overview
The Server API provides methods for managing a self-hosted Vestauth server programmatically. This includes initializing server configuration, starting the server, and managing the PostgreSQL database.For most use cases, you’ll use the CLI commands (
vestauth server start) instead of the programmatic API. The Server API is useful for custom deployment scripts and testing.server.init()
Initializes the server configuration by creating or updating the.env file with server settings.
Signature
Example
Environment Variables Created
This method creates a.env file with:
.env
server.start()
Starts the Vestauth server using configuration from environment variables.Signature
Parameters
number
Port number to listen on. Overrides
PORT environment variable. Defaults to 3000.string
Server hostname. Overrides
HOSTNAME environment variable. Defaults to http://localhost:3000.string
PostgreSQL connection string. Overrides
DATABASE_URL environment variable.Returns
Returns a Node.js HTTP server instance.Example: Basic Usage
Example: Custom Port and Hostname
Example: Full Custom Configuration
server.close()
Gracefully shuts down the Vestauth server.Signature
Example
server.db.create()
Creates thevestauth_production PostgreSQL database.
Signature
Example
server.db.migrate()
Runs database migrations to set up the required tables and schema.Signature
Example
Migrations Applied
This creates the following tables:agents- Stores agent registrationspublic_jwks- Stores agent public keys for discovery
server.db.drop()
Drops thevestauth_production database.
Signature
Example
Complete Setup Example
Here’s a complete script for setting up and running a Vestauth server:Production Deployment
Environment Configuration
For production, set these environment variables:.env
Managed Database
Use a managed PostgreSQL service:Process Manager
Run with a process manager like PM2:Docker Deployment
DNS Configuration
Example DNS Records
Health Checks
Implement health checks for production:Testing
Test your server setup:Monitoring and Logging
The server logs key events:See Also
CLI Server Commands
Command-line interface for server management
Self-Hosting Guide
Complete guide to self-hosting Vestauth
Configuration
Server configuration options
Database Setup
PostgreSQL setup and migrations