Skip to main content

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
Edit the .env file to customize your server configuration before starting.

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 the vestauth_production PostgreSQL database.

Signature

Example

This command requires PostgreSQL to be installed and running, and the user must have database creation privileges.

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 registrations
  • public_jwks - Stores agent public keys for discovery

server.db.drop()

Drops the vestauth_production database.

Signature

Example

This operation is destructive and will delete all agent registrations and keys. Use with caution.

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

Production requirement: Configure a wildcard DNS record for *.${HOSTNAME}.Example: if HOSTNAME=vestauth.yourapp.com, add *.vestauth.yourapp.com.This is required for .well-known discovery per the web-bot-auth specification.

Example DNS Records

Or with CNAME:

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