Files
AIGC/demo/update-hosts.ps1
AIGC Developer 26d10a3322 配置自定义域名开发环境
- 修改hosts文件配置,添加测试域名映射
- 前端API地址改为 api.yourdomain.com:8080
- 后端服务绑定到 api.yourdomain.com:8080
- 前端开发服务器使用 test.yourdomain.com:5173
- 添加自动配置脚本和启动脚本
- 提供完整的域名配置指南和故障排除说明
- 支持更真实的开发环境模拟
2025-10-23 10:40:57 +08:00

42 lines
1.6 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 更新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