deerflow-code/scripts/start-frontend.ps1
2026-09-07 18:24:55 +08:00

42 lines
1.5 KiB
PowerShell

. "$PSScriptRoot\env.ps1"
$PidFile = Join-Path $PidDir "frontend.pid"
$LogFile = Join-Path $LogDir "frontend.log"
if (Test-PidRunning $PidFile) {
$existingPid = Get-Content -LiteralPath $PidFile | Select-Object -First 1
Write-Host "Frontend is already running (pid $existingPid)."
Write-Host "URL: $FrontendPublicBaseUrl"
exit 0
}
$NpmCmd = (Get-Command npm.cmd -ErrorAction SilentlyContinue).Source
if (-not $NpmCmd) {
throw "npm.cmd was not found in PATH. Install Node.js or add npm.cmd to PATH."
}
Remove-Item -LiteralPath $PidFile -Force -ErrorAction SilentlyContinue
Write-Host "Starting frontend..."
Write-Host "Log: $LogFile"
$RunnerFile = Join-Path $RuntimeDir "run-frontend.ps1"
$runner = @"
`$ErrorActionPreference = "Continue"
Set-Location -LiteralPath $(ConvertTo-PSLiteral $FrontendDir)
`$env:VITE_BACKEND_BASE_URL = $(ConvertTo-PSLiteral $BackendPublicBaseUrl)
`$env:VITE_LANGGRAPH_BASE_URL = $(ConvertTo-PSLiteral "$BackendPublicBaseUrl/api")
& $(ConvertTo-PSLiteral $NpmCmd) run dev -- --host $(ConvertTo-PSLiteral $FrontendHost) --port $(ConvertTo-PSLiteral $FrontendPort) *> $(ConvertTo-PSLiteral $LogFile)
"@
Set-Content -LiteralPath $RunnerFile -Value $runner -Encoding UTF8
$proc = Start-Process -FilePath "powershell.exe" -ArgumentList @(
"-NoProfile",
"-ExecutionPolicy", "Bypass",
"-File", $RunnerFile
) -WindowStyle Hidden -PassThru
Set-Content -LiteralPath $PidFile -Value $proc.Id
Write-Host "Frontend started (pid $($proc.Id))."
Write-Host "URL: $FrontendPublicBaseUrl"