LogoRobo.js

Configuration

All configuration options for @robojs/server.

Configure the server plugin through a config file at config/plugins/robojs/server.mjs (or .ts). All fields are optional.

Complete example

config/plugins/robojs/server.mjs
export default {
	port: 3000,
	hostname: '0.0.0.0',
	prefix: '/api',
	maxPortAttempts: 10,
	cors: {
		origins: ['https://myapp.com'],
		credentials: true
	},
	tunnel: {
		enabled: false,
		provider: 'cloudflare'
	},
	openapi: {
		title: 'My API',
		version: '1.0.0'
	}
}
config/plugins/robojs/server.mjs
export default {
	port: 3000,
	hostname: '0.0.0.0',
	prefix: '/api',
	maxPortAttempts: 10,
	cors: {
		origins: ['https://myapp.com'],
		credentials: true
	},
	tunnel: {
		enabled: false,
		provider: 'cloudflare'
	},
	openapi: {
		title: 'My API',
		version: '1.0.0'
	}
}

Options reference

OptionTypeDefaultDescription
portnumber3000 (or PORT env)Port the server listens on.
hostnamestring'localhost' (or ROBO_HOSTNAME env)Hostname to bind to. Use '0.0.0.0' for all interfaces.
prefixstring | false | null'/api'URL prefix for API routes. Set to false or null to disable.
maxPortAttemptsnumber10Max ports to try when the configured port is in use. Set to 1 to disable auto-increment.
corsboolean | CorsConfigundefinedCORS configuration. true enables permissive CORS. See CORS.
engineBaseEngineAuto-detectedCustom server engine. See Engines.
viteViteDevServerAuto-created in devPre-configured Vite dev server instance.
viteBuild{ configFile: string }Auto-discoveredVite config file path for production builds.
tunnelTunnelConfigundefinedTunnel configuration. See Tunnels.
openapiboolean | OpenAPIConfigEnabledOpenAPI spec generation settings. Set to false to disable. See OpenAPI.
pluginPrefixesPluginPrefixMap{}URL prefix mappings for plugin routes.

Port auto-increment

When the configured port is already in use, the server tries the next port automatically (up to maxPortAttempts attempts). A warning is logged:

[server] Port 3000 is in use. Using port 3001 instead.

To disable this behavior:

config/plugins/robojs/server.mjs
export default {
	port: 3000,
	maxPortAttempts: 1
}
config/plugins/robojs/server.mjs
export default {
	port: 3000,
	maxPortAttempts: 1
}

CORS config

// Permissive (all origins)
cors: true

// Specific origins
cors: {
	origins: ['https://myapp.com', 'http://localhost:5173'],
	credentials: true
}
// Permissive (all origins)
cors: true

// Specific origins
cors: {
	origins: ['https://myapp.com', 'http://localhost:5173'],
	credentials: true
}

See CORS for details.

Tunnel config

tunnel: {
	enabled: true,
	provider: 'cloudflare',
	cloudflare: {
		domain: 'example.com',
		apiKey: 'your-api-key',
		zoneId: 'your-zone-id',
		accountId: 'your-account-id'
	}
}
tunnel: {
	enabled: true,
	provider: 'cloudflare',
	cloudflare: {
		domain: 'example.com',
		apiKey: 'your-api-key',
		zoneId: 'your-zone-id',
		accountId: 'your-account-id'
	}
}

See Tunnels for details.

OpenAPI config

openapi: {
	title: 'My API',
	version: '1.0.0',
	servers: [{ url: 'https://api.example.com' }]
}
openapi: {
	title: 'My API',
	version: '1.0.0',
	servers: [{ url: 'https://api.example.com' }]
}

Set openapi: false to disable generation. See OpenAPI for full options.

Plugin prefixes

Scope plugin routes under URL prefixes:

pluginPrefixes: {
	'@robojs/mock': '/mock',
	'@robojs/other': {
		api: '/other-api',
		static: '/other-static',
		exclusive: false
	}
}
pluginPrefixes: {
	'@robojs/mock': '/mock',
	'@robojs/other': {
		api: '/other-api',
		static: '/other-static',
		exclusive: false
	}
}
  • Simple string: Both API and static assets under that prefix, exclusive mode.
  • Object: Separate API and static prefixes, with optional exclusive flag.
  • exclusive: true (default): Plugin routes are ONLY accessible under the prefix.
  • exclusive: false: Plugin routes are accessible both with and without the prefix.

Environment variables

VariableDescriptionDefault
PORTServer port3000
ROBO_HOSTNAMEServer hostname'localhost'
CLOUDFLARE_DOMAINTunnel domain
CLOUDFLARE_API_KEYCloudflare API key
CLOUDFLARE_ZONE_IDCloudflare zone ID
CLOUDFLARE_ACCOUNT_IDCloudflare account ID
CLOUDFLARE_TUNNEL_IDTunnel ID (auto-populated)
CLOUDFLARE_TUNNEL_TOKENTunnel token (auto-populated)
CLOUDFLARED_VERSIONCloudflared binary version'latest'

Next steps

On this page