Files

31 lines
1.1 KiB
PowerShell

# 启动带微信配置的后端(小程序用这个)。
# 用法:pwsh -File .\run-mini.ps1
# pwsh -File .\run-mini.ps1 -Port 8010
param(
[int]$Port = 8000,
[string]$Db = "data/app.db"
)
$ErrorActionPreference = "Stop"
Set-Location $PSScriptRoot
$envFile = Join-Path $PSScriptRoot "data\wx.env"
if (Test-Path $envFile) {
Get-Content $envFile -Encoding UTF8 | ForEach-Object {
$line = $_.Trim()
if ($line -and -not $line.StartsWith("#") -and $line.Contains("=")) {
$i = $line.IndexOf("=")
$k = $line.Substring(0, $i).Trim()
$v = $line.Substring($i + 1).Trim()
if ($v) { Set-Item -Path "env:$k" -Value $v }
}
}
Write-Host "已读取 data\wx.env" -ForegroundColor DarkGray
} else {
Write-Host "没有 data\wx.env,按 dev 模式启动(假 openid,不发真消息)" -ForegroundColor Yellow
}
Write-Host "WX_APPID=$($env:WX_APPID) SECRET=$([bool]$env:WX_SECRET) TMPL_DAILY=$([bool]$env:WX_TMPL_DAILY)" -ForegroundColor DarkGray
Write-Host "接口文档 http://127.0.0.1:$Port/docs" -ForegroundColor Cyan
python -m backend.app --host 127.0.0.1 --port $Port --db $Db