Skip to main content

Configuration

Learn about all configuration options available when setting up Sentro.

ConnectorConfig

The main configuration object passed to the Connector constructor:

type ConnectorConfig = {
  secretKey: string;      // Security key for API authentication
  authKey?: string;        // Header name for authentication
  db: DBConfig;          // Database configuration
  apiUrl?: string;       // Optional base API URL
}

secretKey

A secret key used to authenticate requests to the Connector API. All API requests must include this key in the authentication header.

secretKey: process.env.CONNECTOR_SECRET_KEY!
Security: Never hardcode this value. Use environment variables and keep it secret.

authKey

The HTTP header name that clients must use to send the secret key. Default is "auth".

authKey: "auth"  // Clients send: { "auth": "your-secret-key" }

apiUrl (optional)

Base URL for the API. Useful when deploying behind a proxy or in cloud environments.

apiUrl: "https://api.example.com"

DBConfig

Database connection configuration:

type DBConfig = {
  host: string;           // Database host
  port: number;           // Database port
  user: string;           // Database user
  password: string;       // Database password
  database: string;       // Database name
  schema?: string;        // Schema name (PostgreSQL)
  type: DatabaseType;     // Database type
  ssl?: boolean;       // Optional SSL configuration (depends on database handler)
}

type DatabaseType = 'postgres' | 'mysql' | 'mssql';

PostgreSQL Example

db: {
  host: "localhost",
  port: 5432,
  user: "postgres",
  password: "password",
  database: "myapp",
  schema: "public",
  type: "postgres"
  ssl: false,
}

MySQL Example

db: {
  host: "localhost",
  port: 3306,
  user: "root",
  password: "password",
  database: "myapp",
  type: "mysql"
}

MSSQL Example

db: {
  host: "localhost",
  port: 1433,
  user: "sa",
  password: "YourPassword123!",
  database: "myapp",
  type: "mssql"
}

Environment Variables

Best practice is to use environment variables for sensitive configuration:

.env file

# Connector
CONNECTOR_SECRET_KEY=your-super-secret-key-change-this

# Database
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=your-db-password
DB_NAME=myapp
DB_SCHEMA=public
DB_TYPE=postgres

Using in Code

import 'dotenv/config';

const connector = new Connector({
  secretKey: process.env.CONNECTOR_SECRET_KEY!,
  db: {
    host: process.env.DB_HOST!,
    port: parseInt(process.env.DB_PORT!),
    user: process.env.DB_USER!,
    password: process.env.DB_PASSWORD!,
    database: process.env.DB_NAME!,
    schema: process.env.DB_SCHEMA,
    type: process.env.DB_TYPE as DatabaseType,
    ssl: false
  }
});

Connection Pooling

The SQL database handler (Kysely) uses connection pooling by default. The pool is managed automatically, but you can configure it through Kysely's options if needed.

SSL/TLS Configuration

For production databases, especially cloud-hosted ones, you may need SSL. This is configured at the database handler level:

// For PostgreSQL with SSL
db: {
  host: "your-db.region.rds.amazonaws.com",
  port: 5432,
  user: "dbuser",
  password: process.env.DB_PASSWORD!,
  database: "production",
  type: "postgres",
  ssl: {
    rejectUnauthorized: true,
    ca: fs.readFileSync('./rds-ca-cert.pem').toString()
  }
}
Note: SSL configuration depends on your database handler implementation. Check the Kysely documentation for advanced SSL options.

Multiple Environments

Create different configuration files for each environment:

config/development.ts

export const config = {
  secretKey: "dev-secret-key",
  db: {
    host: "localhost",
    port: 5432,
    user: "postgres",
    password: "password",
    database: "myapp_dev",
    schema: "public",
    type: "postgres" as const
  }
};

config/production.ts

export const config = {
  secretKey: process.env.CONNECTOR_SECRET_KEY!,
  db: {
    host: process.env.DB_HOST!,
    port: parseInt(process.env.DB_PORT!),
    user: process.env.DB_USER!,
    password: process.env.DB_PASSWORD!,
    database: process.env.DB_NAME!,
    schema: process.env.DB_SCHEMA,
    type: process.env.DB_TYPE as "postgres"
  }
};

Loading Configuration

const environment = process.env.NODE_ENV || 'development';
const { config } = await import(`./config/${environment}`);

const connector = new Connector(config);
Next Steps: Learn about ModelCustomizer to customize your tables and add business logic.