Files
AIGC/demo/update-hosts.ps1

42 lines
1.6 KiB
PowerShell
Raw Normal View History

# 更新hosts文件脚本
# 需要管理员权限运行
# 检查是否以管理员身份运行
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "请以管理员身份运行此脚本" -ForegroundColor Red
Write-Host "右键点击PowerShell选择'以管理员身份运行'" -ForegroundColor Yellow
pause
exit
}
$hostsFile = "C:\Windows\System32\drivers\etc\hosts"
$domainMappings = @"
# AIGC Demo 测试域名映射
127.0.0.1 test.yourdomain.com
127.0.0.1 api.yourdomain.com
127.0.0.1 local.yourdomain.com
"@
Write-Host "正在更新hosts文件..." -ForegroundColor Green
# 检查是否已经存在映射
$existingContent = Get-Content $hostsFile -Raw
if ($existingContent -match "test\.yourdomain\.com") {
Write-Host "域名映射已存在,跳过添加" -ForegroundColor Yellow
} else {
# 添加域名映射
Add-Content -Path $hostsFile -Value $domainMappings
Write-Host "域名映射添加成功!" -ForegroundColor Green
}
Write-Host "`n添加的域名映射:" -ForegroundColor Cyan
Write-Host "127.0.0.1 test.yourdomain.com" -ForegroundColor White
Write-Host "127.0.0.1 api.yourdomain.com" -ForegroundColor White
Write-Host "127.0.0.1 local.yourdomain.com" -ForegroundColor White
Write-Host "`n现在可以使用以下域名访问服务:" -ForegroundColor Green
Write-Host "前端: http://test.yourdomain.com:5173" -ForegroundColor Cyan
Write-Host "后端: http://api.yourdomain.com:8080" -ForegroundColor Cyan
pause