Reference

Configuration

How to configure dnax Framework backend.

The dnax Framework backend is configured using the define.Server() function. This page covers all configuration options.

Basic Configuration

import { define, app } from '@dnax/core';

const config = define.Server({
  server: {
    name: 'My API',
    port: 4000,
  },
  tenants: [
    {
      id: 'v1',
      dir: 'v1',
      database: { uri: 'mongodb://localhost:27017/mydb' }
    }
  ]
});

await app.boot(config);

Server Options

OptionTypeDefaultDescription
server.namestring'SERVER'Server name displayed in console
server.portnumber4000Port number
server.corsobject-CORS configuration
server.jwtobject-JWT configuration
server.ipRestrictionobject-IP restriction rules
server.body.maxSizenumber104857600 (100MB)Maximum request body size in bytes
clusterModebooleantrueEnable cluster mode

CORS Configuration

const config = define.Server({
  server: {
    port: 4000,
    cors: {
      origin: '*', // or ['https://example.com']
      credentials: true,
      allowHeaders: ['Content-Type', 'Authorization'],
      allowMethods: ['GET', 'POST', 'PUT', 'DELETE'],
    }
  }
});
OptionTypeDescription
originstring | string[] | functionAllowed origins
credentialsbooleanAllow credentials
allowHeadersstring[]Allowed headers
allowMethodsstring[]Allowed methods

JWT Configuration

const config = define.Server({
  server: {
    port: 4000,
    jwt: {
      secret: 'your-secret-key',
      expiresIn: '7d',
    }
  }
});
OptionTypeDefaultDescription
jwt.secretstring-JWT signing secret
jwt.expiresInstring'7d'Token expiration

Body Size

Control the maximum request body size accepted by the server. Uses Hono Body Limit Middleware under the hood.

const config = define.Server({
  server: {
    port: 4000,
    body: {
      maxSize: 1024 * 1024 * 50, // 50MB
    },
  },
  tenants: [...],
});
OptionTypeDefaultDescription
body.maxSizenumber104857600 (100MB)Maximum request body size in bytes

IP Restriction

Block or allow requests based on client IP address. Uses Hono IP Restriction Middleware under the hood.

const config = define.Server({
  server: {
    port: 4000,
    ipRestriction: {
      denyList: ['10.0.0.0/8', '192.168.0.50'],
      allowList: ['127.0.0.1', '::1', '203.0.113.0/24'],
    },
  },
  tenants: [...],
});
OptionTypeDescription
denyListIPRestrictionRule[]IPs or ranges to block
allowListIPRestrictionRule[]IPs or ranges to allow
denyList takes precedence over allowList. If an IP matches both lists, it is blocked.

Rule Syntax

Rules accept static IPs, CIDR notation, or a wildcard:

FormatIPv4 exampleIPv6 example
Static IP192.168.2.0::1
CIDR192.168.2.0/24::1/10
Wildcard**

Block a Subnet

ipRestriction: {
  denyList: ['10.0.0.0/8'],
}

Allow Only Private Network

ipRestriction: {
  denyList: ['*'],
  allowList: ['192.168.1.0/24', '127.0.0.1', '::1'],
}

Allow Only Specific IPs

ipRestriction: {
  denyList: ['*'],
  allowList: ['203.0.113.10', '203.0.113.20'],
}

Tenants Configuration

See Tenant for a focused reference on dir, URLs, and layout.

Each tenant represents an isolated database and a code root on disk. The field dir is required: it is the path (relative to the process working directory, usually the project root) where dnax looks for {dir}/collections, {dir}/routes, and {dir}/scripts.

const config = define.Server({
  server: { port: 4000 },
  tenants: [
    {
      id: 'v1',
      dir: 'v1',
      name: 'v1',
      database: {
        uri: 'mongodb://localhost:27017/v1_db',
        options: {
          maxPoolSize: 10,
        }
      }
    },
    {
      id: 'tenant2',
      dir: 'tenants/tenant2',
      name: 'Second Tenant',
      database: {
        uri: 'mongodb://localhost:27017/tenant2_db',
      }
    }
  ]
});
OptionTypeRequiredDescription
idstringYesUnique tenant identifier (used in /api/:tenant_id/...)
dirstringYesRelative path to the tenant folder (collections, routes, scripts)
namestringNoTenant display name
routes.prefixstringNoURL prefix for custom routes; required to load routes/**/*.route.ts
database.uristringYesMongoDB connection URI
database.optionsobjectNoMongoDB client options

Cluster Mode

By default, cluster mode is enabled, allowing the server to use multiple processes:

const config = define.Server({
  clusterMode: true, // default
  server: { port: 4000 },
  tenants: [...]
});

When enabled, you can run multiple server instances on the same port using Bun.serve({ reusePort: true }).

Copyright © 2026