84 lines
2.6 KiB
PowerShell
84 lines
2.6 KiB
PowerShell
# Serve the built site.
|
|
#
|
|
# pwsh server/run.ps1 # editable server, port 8080
|
|
# pwsh server/run.ps1 -Port 9000
|
|
# pwsh server/run.ps1 -Port 9000 -ReadOnly # deployment-style preview
|
|
#
|
|
# Editable mode uses serve.py. Read-only mode uses Caddy when server/caddy.exe
|
|
# is present (get it with get-caddy.ps1) and falls back to 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,
|
|
[switch]$ReadOnly
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
Set-Location $here # Caddyfile's `root * ../web` resolves against the cwd
|
|
|
|
if ($Editable -and $ReadOnly) {
|
|
throw '-Editable and -ReadOnly cannot be used together.'
|
|
}
|
|
$editMode = -not $ReadOnly
|
|
|
|
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 = '127.0.0.1'
|
|
try {
|
|
$lanIp = (Get-NetIPConfiguration -ErrorAction Stop |
|
|
Where-Object { $_.IPv4DefaultGateway -and $_.NetAdapter.Status -eq 'Up' } |
|
|
Select-Object -First 1).IPv4Address.IPAddress
|
|
if ($lanIp) { $ip = $lanIp }
|
|
}
|
|
catch {
|
|
# Restricted shells may block the CIM query. Localhost still works.
|
|
}
|
|
|
|
$caddy = Join-Path $here 'caddy.exe'
|
|
$engine = if ($editMode) { 'serve.py (map 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 $editMode -and (Test-Path $caddy)) {
|
|
$env:TARKOVMAP_PORT = "$Port"
|
|
& $caddy run --config (Join-Path $here 'Caddyfile')
|
|
}
|
|
else {
|
|
$python = Join-Path $here '..\.venv\Scripts\python.exe'
|
|
$pythonArgs = @()
|
|
if (-not (Test-Path $python)) {
|
|
$pythonCommand = Get-Command python -ErrorAction SilentlyContinue
|
|
if ($pythonCommand) {
|
|
$python = $pythonCommand.Source
|
|
}
|
|
else {
|
|
$pyCommand = Get-Command py -ErrorAction SilentlyContinue
|
|
if (-not $pyCommand) {
|
|
throw 'Python was not found. Create .venv or install Python.'
|
|
}
|
|
$python = $pyCommand.Source
|
|
$pythonArgs = @('-3')
|
|
}
|
|
}
|
|
if ($editMode) {
|
|
& $python @pythonArgs (Join-Path $here 'serve.py') $Port --editable
|
|
}
|
|
else {
|
|
Write-Host " (run get-caddy.ps1 for the faster server)"
|
|
& $python @pythonArgs (Join-Path $here 'serve.py') $Port
|
|
}
|
|
}
|