create-fluxstack
Version:
⚡ Revolutionary full-stack TypeScript framework with Declarative Config System, Elysia + React + Bun
93 lines (77 loc) • 2.5 kB
text/typescript
/**
* Runtime-Reloadable Configuration
* Configs that can be reloaded without server restart
*/
import { defineReactiveConfig, config } from '@/core/utils/config-schema'
/**
* Runtime app configuration
* Can be reloaded via appRuntimeConfig.reload()
*/
export const appRuntimeConfig = defineReactiveConfig({
// Features that can be toggled in runtime
enableSwagger: config.boolean('ENABLE_SWAGGER', true),
enableMetrics: config.boolean('ENABLE_METRICS', false),
enableMonitoring: config.boolean('ENABLE_MONITORING', false),
enableDebugMode: config.boolean('DEBUG', false),
// Logging level can be changed in runtime
logLevel: config.enum(
'LOG_LEVEL',
['debug', 'info', 'warn', 'error'] as const,
'info'
),
logFormat: config.enum(
'LOG_FORMAT',
['json', 'pretty'] as const,
'pretty'
),
// Rate limiting
rateLimitEnabled: config.boolean('RATE_LIMIT_ENABLED', true),
rateLimitMax: {
type: 'number' as const,
env: 'RATE_LIMIT_MAX',
default: 100,
validate: (value: number) => value > 0 || 'Rate limit must be positive'
},
rateLimitWindow: {
type: 'number' as const,
env: 'RATE_LIMIT_WINDOW',
default: 60000,
description: 'Rate limit window in milliseconds'
},
// Request timeout
requestTimeout: {
type: 'number' as const,
env: 'REQUEST_TIMEOUT',
default: 30000,
validate: (value: number) => value > 0 || 'Timeout must be positive'
},
// Max upload size
maxUploadSize: {
type: 'number' as const,
env: 'MAX_UPLOAD_SIZE',
default: 10485760, // 10MB
validate: (value: number) => value > 0 || 'Max upload size must be positive'
},
// Allowed origins (can be updated in runtime)
corsOrigins: config.array('CORS_ORIGINS', ['*']),
// Maintenance mode
maintenanceMode: config.boolean('MAINTENANCE_MODE', false),
maintenanceMessage: config.string(
'MAINTENANCE_MESSAGE',
'System is under maintenance. Please try again later.'
)
})
/**
* Setup config watcher with logging
*/
appRuntimeConfig.watch((newConfig) => {
console.log('🔄 Runtime config reloaded:')
console.log(' Debug:', newConfig.enableDebugMode)
console.log(' Log Level:', newConfig.logLevel)
console.log(' Maintenance:', newConfig.maintenanceMode)
})
/**
* Export type
*/
export type AppRuntimeConfig = typeof appRuntimeConfig.values
export default appRuntimeConfig