51 lines
1.6 KiB
PowerShell
51 lines
1.6 KiB
PowerShell
# Serve the built site.
|
|
#
|
|
# pwsh server/run.ps1 # port 8080
|
|
# pwsh server/run.ps1 -Port 9000
|
|
# pwsh server/run.ps1 -Port 9000 -Editable # enable placement saves
|
|
#
|
|
# Uses Caddy when server/caddy.exe is present (get it with get-caddy.ps1) and
|
|
# falls back to the dependency-free serve.py otherwise. Caddy is roughly 3x
|
|
# faster at low concurrency and does not fall over at high concurrency -- see
|
|
# the table in the README.
|
|
|
|
param(
|
|
[int]$Port = 8080,
|
|
[switch]$Editable
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
Set-Location $here # Caddyfile's `root * ../web` resolves against the cwd
|
|
|
|
if (-not (Test-Path (Join-Path $here '..\web\data\world.json'))) {
|
|
Write-Warning "web/data/world.json missing -- run 'python tools/build.py' first"
|
|
}
|
|
|
|
$ip = (Get-NetIPConfiguration |
|
|
Where-Object { $_.IPv4DefaultGateway -and $_.NetAdapter.Status -eq 'Up' } |
|
|
Select-Object -First 1).IPv4Address.IPAddress
|
|
if (-not $ip) { $ip = '127.0.0.1' }
|
|
|
|
$caddy = Join-Path $here 'caddy.exe'
|
|
$engine = if ($Editable) { 'serve.py (placement editing enabled)' }
|
|
elseif (Test-Path $caddy) { 'caddy' }
|
|
else { 'serve.py (slower)' }
|
|
|
|
Write-Host ""
|
|
Write-Host " serving with $engine"
|
|
Write-Host " local http://localhost:$Port/"
|
|
Write-Host " LAN http://${ip}:$Port/"
|
|
Write-Host ""
|
|
Write-Host " Ctrl+C to stop"
|
|
Write-Host ""
|
|
|
|
if (-not $Editable -and (Test-Path $caddy)) {
|
|
$env:TARKOVMAP_PORT = "$Port"
|
|
& $caddy run --config (Join-Path $here 'Caddyfile')
|
|
}
|
|
else {
|
|
if (-not $Editable) { Write-Host " (run get-caddy.ps1 for the faster server)" }
|
|
python (Join-Path $here 'serve.py') $Port
|
|
}
|