build: add server-rs local dev scripts
This commit is contained in:
52
server-rs/scripts/dev.ps1
Normal file
52
server-rs/scripts/dev.ps1
Normal file
@@ -0,0 +1,52 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Alias("h")]
|
||||
[switch]$Help,
|
||||
[string]$ApiHost = "127.0.0.1",
|
||||
[int]$Port = 3000,
|
||||
[string]$Log = "info,tower_http=info"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Usage {
|
||||
@(
|
||||
'Usage:'
|
||||
' ./server-rs/scripts/dev.ps1'
|
||||
' ./server-rs/scripts/dev.ps1 -ApiHost 0.0.0.0 -Port 3100 -Log "debug,tower_http=debug"'
|
||||
''
|
||||
'Notes:'
|
||||
' 1. Set default local env vars for the Rust api-server'
|
||||
' 2. Start Axum with cargo run -p api-server'
|
||||
' 3. This script only covers the api-server local dev loop'
|
||||
) -join [Environment]::NewLine
|
||||
}
|
||||
|
||||
if ($Help) {
|
||||
Write-Usage
|
||||
exit 0
|
||||
}
|
||||
|
||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$serverRsDir = Split-Path -Parent $scriptDir
|
||||
|
||||
if (-not (Test-Path (Join-Path $serverRsDir "Cargo.toml"))) {
|
||||
throw "Missing server-rs/Cargo.toml, cannot start local dev script."
|
||||
}
|
||||
|
||||
$env:GENARRATIVE_API_HOST = $ApiHost
|
||||
$env:GENARRATIVE_API_PORT = "$Port"
|
||||
$env:GENARRATIVE_API_LOG = $Log
|
||||
|
||||
Write-Host "[server-rs:dev] working dir: $serverRsDir"
|
||||
Write-Host "[server-rs:dev] GENARRATIVE_API_HOST=$($env:GENARRATIVE_API_HOST)"
|
||||
Write-Host "[server-rs:dev] GENARRATIVE_API_PORT=$($env:GENARRATIVE_API_PORT)"
|
||||
Write-Host "[server-rs:dev] GENARRATIVE_API_LOG=$($env:GENARRATIVE_API_LOG)"
|
||||
|
||||
Push-Location $serverRsDir
|
||||
try {
|
||||
cargo run -p api-server --manifest-path (Join-Path $serverRsDir "Cargo.toml")
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
Reference in New Issue
Block a user