redirector-cli
v1.0.0
Published
Global CLI tool for managing Redirector backend services with Docker Compose
Downloads
5
Maintainers
Readme
Redirector CLI
A global CLI tool for managing Redirector backend services with Docker Compose. Deploy and manage your Redirector API anywhere with zero configuration.
🚀 Quick Start
# Install globally
npm install -g redirector-cli
# Initialize project
mkdir my-redirector && cd my-redirector
redirector setup
# Start services
redirector start
# Check status
redirector statusYour Redirector API will be available at http://localhost:3000!
📋 Requirements
- Node.js 16.0.0 or higher
- Docker and Docker Compose
- npm or yarn
🛠 Installation
Global Installation (Recommended)
npm install -g redirector-cliLocal Installation
npx redirector-cli setup📖 Commands
redirector setup
Initialize a new Redirector project in the current directory.
redirector setup [options]
Options:
-p, --port <number> Backend API port (default: 3000)
--postgres-port <number> PostgreSQL port (default: 5432)
-u, --docker-username <username> Docker Hub username (default: shivarajbakale)
-f, --force Overwrite existing configuration
--no-interactive Skip interactive promptsExamples:
# Interactive setup
redirector setup
# Non-interactive with custom port
redirector setup --port 8080 --no-interactive
# Force overwrite existing project
redirector setup --forceredirector start
Start all Redirector services.
redirector start [options]
Options:
--no-detach Run in foreground (not detached)
--pull Pull latest images before starting
--build Build images before startingExamples:
# Start services in background
redirector start
# Start with latest images
redirector start --pull
# Start in foreground
redirector start --no-detachredirector stop
Stop all Redirector services.
redirector stop [options]
Options:
-v, --remove-volumes Also remove volumes and dataExamples:
# Stop services
redirector stop
# Stop and remove all data
redirector stop --remove-volumesredirector restart
Restart all Redirector services.
redirector restart [options]
Options:
--pull Pull latest images before restartingredirector reset
Stop services and remove all data and volumes.
redirector reset [options]
Options:
-f, --force Skip confirmation prompt
-y, --confirm Automatically confirm reset⚠️ Warning: This will permanently delete all data!
redirector status
Show status of all services.
redirector status [options]
Options:
-j, --json Output status as JSON
-v, --verbose Show detailed informationExamples:
# Human-readable status
redirector status
# JSON output for scripts
redirector status --json
# Detailed information
redirector status --verboseredirector logs
Show logs for services.
redirector logs [service] [options]
Arguments:
service Service name (backend, postgres, or all)
Options:
-f, --follow Follow log output
-t, --tail <number> Number of lines to show from end of logsExamples:
# Show all logs
redirector logs
# Show backend logs only
redirector logs backend
# Follow all logs
redirector logs --follow
# Follow backend logs
redirector logs backend --follow🔧 Configuration
The CLI uses the following configuration sources (in order of precedence):
- Command-line options
- Environment variables
.redirector.jsonfile- Default values
Environment Variables
BACKEND_PORT=3000 # Backend API port
POSTGRES_PORT=5432 # PostgreSQL port
DOCKER_USERNAME=shivarajbakale # Docker Hub username
PROJECT_NAME=redirector # Project name
NODE_ENV=production # Environment (production/development)Configuration File
The CLI creates a .redirector.json file in your project:
{
"backendPort": 3000,
"postgresPort": 5432,
"dockerUsername": "shivarajbakale",
"projectName": "my-project",
"environment": "production"
}🏗 Project Structure
After running redirector setup, your project will contain:
my-redirector/
├── docker-compose.yml # Docker Compose configuration
├── .env # Environment variables
├── .redirector.json # CLI configuration
├── .gitignore # Git ignore rules
├── README.md # Project documentation
└── data/ # Volume mount directory🌐 API Endpoints
Once started, your Redirector API provides:
- Health Check:
GET /health - Groups:
GET /groups/list,POST /groups/create - Requests:
GET /requests,POST /requests/create
Full API documentation: Redirector API Docs
🐳 Docker Images
The CLI uses pre-built Docker images:
- Backend:
shivarajbakale/redirector-backend:latest - Database:
postgres:15
Images are automatically pulled when starting services.
🔍 Troubleshooting
Docker Issues
# Check Docker installation
docker --version
docker compose version
# Check Docker daemon
docker info
# Check running containers
docker psPort Conflicts
# Check if port is in use
lsof -i :3000
# Use custom port
redirector setup --port 8080Service Health
# Check service status
redirector status
# View service logs
redirector logs
# Test API health
curl http://localhost:3000/healthReset Everything
# Complete reset
redirector reset --force
# Restart setup
redirector setup --force🧪 Development
Building from Source
# Clone repository
git clone https://github.com/shivarajbakale/redirector-app.git
cd redirector-app/packages/backend/cli
# Install dependencies
npm install
# Build
npm run build
# Test locally
npm link
redirector --helpRunning Tests
# Run all tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watchLinting
# Check code style
npm run lint
# Fix code style
npm run lint:fix📝 Examples
Basic Usage
# Create new project
mkdir my-api && cd my-api
redirector setup
# Start services
redirector start
# Test API
curl http://localhost:3000/health
# Stop services
redirector stopCustom Configuration
# Setup with custom ports
redirector setup --port 8080 --postgres-port 5433
# Start with latest images
redirector start --pull
# Monitor logs
redirector logs --followProduction Deployment
# Setup production environment
redirector setup --no-interactive
export NODE_ENV=production
# Start services
redirector start
# Monitor status
redirector status --jsonCI/CD Integration
#!/bin/bash
# deploy.sh
# Install CLI
npm install -g redirector-cli
# Setup project
redirector setup --no-interactive --force
# Start services
redirector start --pull
# Wait for health check
until curl -f http://localhost:3000/health; do
echo "Waiting for API..."
sleep 5
done
echo "Deployment successful!"🤝 Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 Links
- Main Repository: redirector-app
- Docker Hub: shivarajbakale/redirector-backend
- npm Package: redirector-cli
- Issues: GitHub Issues
🙏 Support
If you find this project helpful, please consider:
- ⭐ Starring the repository
- 🐛 Reporting bugs
- 💡 Suggesting features
- 📖 Improving documentation
Made with ❤️ by Shivaraj Bakale
