-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-proxy.ps1
More file actions
39 lines (31 loc) · 1.25 KB
/
Copy pathstart-proxy.ps1
File metadata and controls
39 lines (31 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
$Node = (Get-Command node.exe).Source
if (-not $env:PORT) {
$env:PORT = "8787"
}
if ((-not $env:UPSTREAM_ORIGIN) -or ($env:UPSTREAM_ORIGIN -eq "http://y3.ainiaini.xyz")) {
$env:UPSTREAM_ORIGIN = "https://api.finalval.com"
}
$existing = Get-NetTCPConnection -LocalAddress 127.0.0.1 -LocalPort ([int]$env:PORT) -State Listen -ErrorAction SilentlyContinue
if ($existing) {
$owners = ($existing | Select-Object -ExpandProperty OwningProcess -Unique) -join ", "
throw "Port 127.0.0.1:$($env:PORT) is already listening. Owning PID(s): $owners"
}
$stdout = Join-Path $Root "proxy.stdout.log"
$stderr = Join-Path $Root "proxy.stderr.log"
$pidFile = Join-Path $Root ".proxy.pid"
$process = Start-Process `
-FilePath $Node `
-ArgumentList @((Join-Path $Root "proxy.mjs")) `
-WorkingDirectory $Root `
-WindowStyle Hidden `
-RedirectStandardOutput $stdout `
-RedirectStandardError $stderr `
-PassThru
Set-Content -LiteralPath $pidFile -Value $process.Id -Encoding ASCII
Write-Host "transparent-api-proxy started"
Write-Host "PID: $($process.Id)"
Write-Host "URL: http://127.0.0.1:$($env:PORT)"
Write-Host "Upstream: $($env:UPSTREAM_ORIGIN)"
Write-Host "Logs: $stdout ; $stderr"