配置自定义域名开发环境

- 修改hosts文件配置,添加测试域名映射
- 前端API地址改为 api.yourdomain.com:8080
- 后端服务绑定到 api.yourdomain.com:8080
- 前端开发服务器使用 test.yourdomain.com:5173
- 添加自动配置脚本和启动脚本
- 提供完整的域名配置指南和故障排除说明
- 支持更真实的开发环境模拟
This commit is contained in:
AIGC Developer
2025-10-23 10:40:57 +08:00
parent 68574fe33f
commit 26d10a3322
9 changed files with 483 additions and 5 deletions

View File

@@ -0,0 +1,52 @@
# AIGC Demo - 使用域名启动服务
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "AIGC Demo - 使用域名启动服务" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 检查域名解析
Write-Host "检查hosts文件配置..." -ForegroundColor Yellow
try {
$pingResult = Test-NetConnection -ComputerName "test.yourdomain.com" -Port 80 -InformationLevel Quiet
if (-not $pingResult) {
Write-Host "[错误] 域名解析失败请先配置hosts文件" -ForegroundColor Red
Write-Host "请运行: .\update-hosts.ps1 或手动编辑hosts文件" -ForegroundColor Yellow
Write-Host ""
Write-Host "需要添加以下映射到 C:\Windows\System32\drivers\etc\hosts:" -ForegroundColor Yellow
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
Read-Host "按回车键退出"
exit 1
}
} catch {
Write-Host "[错误] 无法检查域名解析" -ForegroundColor Red
Read-Host "按回车键退出"
exit 1
}
Write-Host "[成功] 域名解析正常" -ForegroundColor Green
Write-Host ""
# 启动后端服务
Write-Host "启动后端服务 (api.yourdomain.com:8080)..." -ForegroundColor Yellow
Start-Process -FilePath "cmd" -ArgumentList "/k", "cd /d $PWD && mvn spring-boot:run" -WindowStyle Normal
Write-Host "等待后端服务启动..." -ForegroundColor Yellow
Start-Sleep -Seconds 10
# 启动前端服务
Write-Host "启动前端服务 (test.yourdomain.com:5173)..." -ForegroundColor Yellow
Start-Process -FilePath "cmd" -ArgumentList "/k", "cd /d $PWD\frontend && npm run dev" -WindowStyle Normal
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "服务启动完成!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "前端地址: http://test.yourdomain.com:5173" -ForegroundColor Cyan
Write-Host "后端地址: http://api.yourdomain.com:8080" -ForegroundColor Cyan
Write-Host "API地址: http://api.yourdomain.com:8080/api" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Read-Host "按回车键退出"