- Overview
- Installation
- Quick Start
- Commands Reference
- Configuration Guide
- Use Cases
- Examples
- Troubleshooting
FlexGate CLI is a command-line tool for managing FlexGate configuration without Admin UI. Perfect for:
- 🖥️ EC2/Cloud Instances - Configure via SSH
- 🐳 Docker/Containers - Automated setup
- 🚀 CI/CD Pipelines - Scripted deployment
- 📝 Infrastructure as Code - JSON configuration files
- 🔧 Headless Servers - No browser needed
npm install -g flexgate-proxyVerify:
flexgate --version
# Output: 0.1.0-beta.4npm install flexgate-proxy
npx flexgate --helpflexgate init --interactiveInteractive Wizard:
🚀 FlexGate Configuration Wizard
? Server port: 3000
? Environment: production
? Database host: localhost
? Database port: 5432
? Database name: flexgate
? Database user: flexgate
? Database password: ********
? Redis host: localhost
? Redis port: 6379
? Enable Prometheus metrics? Yes
✅ Configuration saved to: config/flexgate.json
✅ Environment file generated: .env
flexgate config showflexgate db test
flexgate redis testnpm startDone! 🎉
Initialize FlexGate configuration.
Syntax:
flexgate init [options]Options:
-i, --interactive- Interactive configuration wizard-f, --force- Overwrite existing configuration
Examples:
# Interactive setup (recommended)
flexgate init --interactive
# Use defaults
flexgate init
# Force overwrite
flexgate init --forceDisplay current configuration.
Syntax:
flexgate config show [options]Options:
--json- Output as JSON
Examples:
# Human-readable format
flexgate config show
# JSON format
flexgate config show --jsonOutput:
📋 Current Configuration:
Server:
Port: 3000
Host: 0.0.0.0
Environment: production
Database:
Host: localhost:5432
Name: flexgate
User: flexgate
SSL: false
Redis:
Host: localhost:6379
Database: 0
Security:
CORS Enabled: true
Rate Limiting: true
Logging:
Level: info
Format: json
Monitoring:
Metrics: true
Prometheus Port: 9090
Set a configuration value.
Syntax:
flexgate config set <key> <value>Examples:
# Server
flexgate config set server.port 8080
flexgate config set server.host "0.0.0.0"
flexgate config set server.environment production
# Database
flexgate config set database.host db.example.com
flexgate config set database.port 5432
flexgate config set database.name flexgate_prod
flexgate config set database.user flexgate_user
flexgate config set database.password secret123
flexgate config set database.ssl true
flexgate config set database.poolMax 20
# Redis
flexgate config set redis.host redis.example.com
flexgate config set redis.port 6379
flexgate config set redis.password redissecret
flexgate config set redis.db 1
# Security
flexgate config set security.corsEnabled true
flexgate config set security.rateLimitEnabled true
flexgate config set security.rateLimitMaxRequests 1000
# Logging
flexgate config set logging.level debug
flexgate config set logging.format json
flexgate config set logging.destination both
# Monitoring
flexgate config set monitoring.metricsEnabled true
flexgate config set monitoring.prometheusPort 9090What It Does:
- Updates
config/flexgate.json - Regenerates
.envfile - Validates the value
- Confirms the change
Get a configuration value.
Syntax:
flexgate config get <key>Examples:
flexgate config get server.port
# Output: 3000
flexgate config get database.host
# Output: localhost
flexgate config get logging.level
# Output: infoImport configuration from JSON file.
Syntax:
flexgate config import <file>Examples:
# Import production config
flexgate config import config/flexgate.production.json.example
# Import from custom path
flexgate config import /opt/flexgate-config.json
# Import backup
flexgate config import /tmp/flexgate-backup.jsonWhat It Does:
- Reads JSON file
- Validates against schema
- Saves to
config/flexgate.json - Regenerates
.env - Displays imported configuration
Export configuration to JSON file.
Syntax:
flexgate config export <file>Examples:
# Export to file
flexgate config export backup.json
# Export with timestamp
flexgate config export backup-$(date +%Y%m%d).json
# Export to specific path
flexgate config export /tmp/flexgate-backup.jsonUse Case: Backup, share configs, version control
Reset configuration to defaults.
Syntax:
flexgate config reset [options]Options:
-f, --force- Skip confirmation
Examples:
# With confirmation
flexgate config reset
# Skip confirmation
flexgate config reset --forceWarning: This will erase all custom configuration!
Test PostgreSQL database connection.
Syntax:
flexgate db testExample:
flexgate db testOutput (Success):
Testing database connection...
✅ Database connection successful
Host: localhost:5432
Database: flexgate
User: flexgate
SSL: false
Output (Failure):
Testing database connection...
❌ Database connection failed
Error: Connection timeout
Host: localhost:5432
Test Redis connection.
Syntax:
flexgate redis testExample:
flexgate redis testOutput (Success):
Testing Redis connection...
✅ Redis connection successful
Host: localhost:6379
Database: 0
Ping: PONG
Output (Failure):
Testing Redis connection...
❌ Redis connection failed
Error: ECONNREFUSED
Host: localhost:6379
Check all services health.
Syntax:
flexgate healthExample:
flexgate healthOutput:
🏥 Running health checks...
✅ FlexGate API: healthy
✅ PostgreSQL: healthy
✅ Redis: healthy
✅ Admin UI: healthy
Location: config/flexgate.json
Structure:
{
"server": {
"port": 3000,
"host": "0.0.0.0",
"environment": "production"
},
"database": {
"host": "localhost",
"port": 5432,
"name": "flexgate",
"user": "flexgate",
"password": "flexgate",
"ssl": false,
"poolMin": 2,
"poolMax": 10
},
"redis": {
"host": "localhost",
"port": 6379,
"password": "",
"db": 0
},
"security": {
"corsOrigins": ["http://localhost:3001"],
"corsEnabled": true,
"rateLimitEnabled": true,
"rateLimitWindowMs": 60000,
"rateLimitMaxRequests": 100
},
"logging": {
"level": "info",
"format": "json",
"destination": "file",
"maxFiles": 10,
"maxSize": "10m"
},
"monitoring": {
"metricsEnabled": true,
"prometheusPort": 9090,
"healthCheckInterval": 30000
}
}Create separate configs for each environment:
config/
flexgate.development.json
flexgate.staging.json
flexgate.production.json
Load:
NODE_ENV=production npm start# 1. SSH into EC2
ssh -i key.pem ec2-user@ec2-instance
# 2. Install FlexGate
npm install -g flexgate-proxy
# 3. Configure
flexgate init --interactive
# 4. Test
flexgate db test
flexgate redis test
# 5. Start
npm startDockerfile:
FROM node:18-alpine
WORKDIR /app
# Install FlexGate
RUN npm install -g flexgate-proxy
# Copy configuration
COPY config/flexgate.json /app/config/flexgate.json
# Generate .env
RUN flexgate config import /app/config/flexgate.json
EXPOSE 8080
CMD ["npm", "start"]Jenkins (Jenkinsfile):
stage('Configure FlexGate') {
steps {
sh 'npm install -g flexgate-proxy'
sh 'flexgate config import config/production.json'
sh 'flexgate db test'
sh 'flexgate redis test'
}
}# 1. Edit configuration
vim config/flexgate.production.json
# 2. Commit to git
git add config/flexgate.production.json
git commit -m "Update production config"
git push
# 3. Deploy
flexgate config import config/flexgate.production.json
npm startConfigure multiple values at once:
#!/bin/bash
flexgate config set server.port 8080
flexgate config set database.host db-prod.internal
flexgate config set database.ssl true
flexgate config set redis.host redis-prod.internal
flexgate config set logging.level warn
flexgate config set monitoring.metricsEnabled true#!/bin/bash
set -e
echo "🚀 FlexGate EC2 Setup"
# Install Node.js
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
sudo yum install -y nodejs
# Install FlexGate
sudo npm install -g flexgate-proxy
# Configure
flexgate init --force <<EOF
8080
production
flexgate-db.xxxx.us-east-1.rds.amazonaws.com
5432
flexgate_prod
flexgate_user
SECURE_PASSWORD
flexgate-redis.xxxxx.cache.amazonaws.com
6379
REDIS_PASSWORD
0
yes
EOF
# Test connections
echo "Testing database..."
flexgate db test || exit 1
echo "Testing Redis..."
flexgate redis test || exit 1
# Health check
flexgate health
echo "✅ FlexGate setup complete!"
echo "Run: npm start"config/flexgate.production.json:
{
"server": {
"port": 8080,
"host": "0.0.0.0",
"environment": "production"
},
"database": {
"host": "flexgate-db.internal",
"port": 5432,
"name": "flexgate_prod",
"user": "flexgate_user",
"password": "${DB_PASSWORD}",
"ssl": true,
"poolMin": 5,
"poolMax": 20
},
"redis": {
"host": "flexgate-redis.internal",
"port": 6379,
"password": "${REDIS_PASSWORD}",
"db": 0
},
"security": {
"corsOrigins": ["https://admin.example.com"],
"corsEnabled": true,
"rateLimitEnabled": true,
"rateLimitMaxRequests": 1000
},
"logging": {
"level": "warn",
"format": "json",
"destination": "both",
"maxFiles": 30,
"maxSize": "100m"
},
"monitoring": {
"metricsEnabled": true,
"prometheusPort": 9090,
"healthCheckInterval": 30000
}
}Deploy:
export DB_PASSWORD="secure_db_password"
export REDIS_PASSWORD="secure_redis_password"
flexgate config import config/flexgate.production.json
npm startError:
Error: Configuration file not found: config/flexgate.json
Solution:
flexgate init --interactiveError:
Error: Port must be between 1 and 65535
Solution:
# Check valid range
flexgate config set server.port 8080
# View current value
flexgate config get server.portError:
❌ Database connection failed
Error: Connection timeout
Solution:
# Verify config
flexgate config get database.host
flexgate config get database.port
# Update if needed
flexgate config set database.host correct-host
flexgate db testError:
❌ Redis connection failed
Error: ECONNREFUSED
Solution:
# Check Redis config
flexgate config show
# Test connection
flexgate redis test
# Update if needed
flexgate config set redis.host correct-hostError:
Error: Invalid JSON in file
Solution:
# Validate JSON syntax
cat config/flexgate.json | jq .
# Or reset and reconfigure
flexgate config reset --force
flexgate init --interactiveFlexGate loads configuration in this order (later overrides earlier):
- Default values (in code)
- JSON configuration (
config/flexgate.json) - Environment variables (
.env) - CLI arguments (if provided)
Example:
# JSON: port = 3000
# ENV: PORT=8080
# CLI: --port 9000
# Result: 9000 (CLI wins)flexgate db test && flexgate redis test && echo "✅ Ready" || echo "❌ Not ready"flexgate config export backup-$(date +%Y%m%d).jsongit add config/flexgate.production.json
git commit -m "Update production database host"Bad:
{"database": {"password": "plaintext_password"}}Good:
{"database": {"password": "${DB_PASSWORD}"}}flexgate config import production.json
flexgate config show
flexgate healthFlexGate CLI provides three configuration methods:
- Admin UI - Visual, localhost:3001
- CLI - Terminal, this tool
- JSON - Direct file editing
Choose CLI for:
- ✅ EC2/cloud instances
- ✅ Headless servers
- ✅ CI/CD automation
- ✅ Quick configuration changes
- ✅ Connection testing
No browser needed! 🚀
- Full Guide:
CLI_JSON_CONFIGURATION_GUIDE.md - Quick Reference:
CLI_QUICK_REFERENCE.md - Troubleshooting:
TROUBLESHOOTING_GUIDE.md - API Documentation:
docs/api.md