Files
Pennyzo-Frontend/scripts/set-env.ps1
ectasy663 ebb7fcaac8 Fix API endpoint configuration with environment-aware URLs
- Add environment-based API URL configuration (dev: localhost:8000, prod: api.pennyzo.com)
- Update PennyzoApiService to use centralized config with timeout settings
- Fix API status checker scripts to load .env variables using dotenv
- Add environment management scripts (set-env.ps1) with npm shortcuts
- Create comprehensive configuration testing and validation tools
- Add TypeScript definitions for Vite environment variables
- Update all documentation with new environment configuration instructions
- Install dotenv package for Node.js environment variable loading
- All APIs now correctly use environment-appropriate URLs automatically
2025-09-25 14:40:20 +05:30

110 lines
3.3 KiB
PowerShell

#!/usr/bin/env powershell
# Environment Configuration Helper Script
# This script helps you switch between development and production API endpoints
param(
[Parameter(Mandatory = $false)]
[ValidateSet("dev", "development", "prod", "production", "local")]
[string]$Environment = "dev",
[switch]$Show
)
$EnvFile = ".env"
$EnvExampleFile = ".env.example"
function Show-CurrentConfig {
Write-Host "Current Environment Configuration:" -ForegroundColor Green
Write-Host "=================================" -ForegroundColor Green
if (Test-Path $EnvFile) {
$content = Get-Content $EnvFile
foreach ($line in $content) {
if ($line -match "VITE_API_BASE_URL=(.+)") {
Write-Host "API Base URL: " -NoNewline -ForegroundColor Yellow
Write-Host $matches[1] -ForegroundColor White
}
if ($line -match "NODE_ENV=(.+)") {
Write-Host "Node Environment: " -NoNewline -ForegroundColor Yellow
Write-Host $matches[1] -ForegroundColor White
}
}
}
else {
Write-Host "No .env file found. Using default configuration." -ForegroundColor Red
Write-Host "API Base URL: " -NoNewline -ForegroundColor Yellow
Write-Host "http://localhost:8000 (development default)" -ForegroundColor White
}
Write-Host ""
}
function Set-Environment {
param([string]$Env)
$apiUrl = ""
$nodeEnv = ""
switch ($Env.ToLower()) {
{ $_ -in @("dev", "development", "local") } {
$apiUrl = "http://localhost:8000"
$nodeEnv = "development"
Write-Host "Configuring for DEVELOPMENT environment..." -ForegroundColor Green
}
{ $_ -in @("prod", "production") } {
$apiUrl = "https://api.pennyzo.com/api/v1/general"
$nodeEnv = "production"
Write-Host "Configuring for PRODUCTION environment..." -ForegroundColor Green
}
default {
Write-Host "Unknown environment: $Env" -ForegroundColor Red
return
}
}
# Create .env content
$debugValue = if ($nodeEnv -eq "development") { "true" } else { "false" }
$logLevel = if ($nodeEnv -eq "development") { "INFO" } else { "WARN" }
$envContent = @"
# Environment Configuration - Auto-generated
# Generated on: $(Get-Date -Format "yyyy-MM-dd HH:mm:ss")
# API Base URL
VITE_API_BASE_URL=$apiUrl
# Environment
NODE_ENV=$nodeEnv
# Debug settings
DEBUG=$debugValue
LOG_LEVEL=$logLevel
# API Status Checker Credentials (optional)
# PENNYZO_TEST_EMAIL=your-test-email@example.com
# PENNYZO_TEST_PASSWORD=your-test-password
"@
# Write to .env file
$envContent | Out-File -FilePath $EnvFile -Encoding UTF8
Write-Host "Environment configured successfully!" -ForegroundColor Green
Write-Host "API Base URL set to: " -NoNewline -ForegroundColor Yellow
Write-Host $apiUrl -ForegroundColor White
Write-Host ""
}
# Main execution
if ($Show) {
Show-CurrentConfig
}
else {
Set-Environment -Env $Environment
Show-CurrentConfig
Write-Host "Usage Examples:" -ForegroundColor Cyan
Write-Host " .\scripts\set-env.ps1 dev # Set development environment" -ForegroundColor Gray
Write-Host " .\scripts\set-env.ps1 prod # Set production environment" -ForegroundColor Gray
Write-Host " .\scripts\set-env.ps1 -Show # Show current configuration" -ForegroundColor Gray
Write-Host ""
Write-Host "Restart your development server for changes to take effect." -ForegroundColor Yellow
}