refactor(app port): changed to have the port be dyncamic on the iis side

docker will default to 8080 and can be adjusted via the docker compose, or passing the same env over
it will change it as well.
This commit is contained in:
2025-07-23 07:36:18 -05:00
parent 13e282e815
commit 074032f20d
3 changed files with 38 additions and 2 deletions

View File

@@ -1,6 +1,9 @@
# uncomment this out to run in productions # uncomment this out to run in productions
# APP_ENV=production # APP_ENV=production
# Server port that will allow vite to talk to the backend.
VITE_SERVER_PORT=4000
# lstv2 loc # lstv2 loc
LSTV2="C\drive\loc" LSTV2="C\drive\loc"

View File

@@ -25,6 +25,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"lst.net/cmd/services/logging" "lst.net/cmd/services/logging"
"lst.net/cmd/services/system/config"
_ "lst.net/docs" _ "lst.net/docs"
"lst.net/utils/db" "lst.net/utils/db"
) )
@@ -110,10 +111,16 @@ func main() {
}) })
logging.RegisterLoggerRoutes(r, basePath) logging.RegisterLoggerRoutes(r, basePath)
config.RegisterConfigRoutes(r, basePath)
r.Any(basePath+"/api", errorApiLoc) r.Any(basePath+"/api", errorApiLoc)
r.Run(":8080") // get the server port
port := "8080"
if os.Getenv("VITE_SERVER_PORT") != "" {
port = os.Getenv("VITE_SERVER_PORT")
}
r.Run(":" + port)
} }
// func serveViteApp(c *gin.Context) { // func serveViteApp(c *gin.Context) {

View File

@@ -94,9 +94,10 @@ function Update-BuildNumber {
Push-Location $rootDir/backend Push-Location $rootDir/backend
Write-Host "Building the app" Write-Host "Building the app"
go get go get
swag init -o swagger -g main.go # swag init -o swagger -g main.go
go build -ldflags "-X main.version=$($version)-$($initialBuildValue)" -o lst_app.exe ./main.go go build -ldflags "-X main.version=$($version)-$($initialBuildValue)" -o lst_app.exe ./main.go
if ($LASTEXITCODE -ne 0) { if ($LASTEXITCODE -ne 0) {
Write-Warning "app build failed!" Write-Warning "app build failed!"
@@ -124,6 +125,22 @@ function Update-BuildNumber {
Write-Host "Building wrapper" Write-Host "Building wrapper"
Push-Location $rootDir/LstWrapper Push-Location $rootDir/LstWrapper
Write-Host "Changing the port to match the server port in the env file"
$port = $env:VITE_SERVER_PORT
if (-not $port) {
$port = "8080" # Default port if env var not set
}
$webConfigPath = "web.config"
$content = Get-Content -Path $webConfigPath -Raw
$newContent = $content -replace '(?<=Rewrite" url="http://localhost:)\d+(?=/\{R:1\}")', $port
$newContent | Set-Content -Path $webConfigPath -NoNewline
Write-Host "Updated web.config rewrite port to $port"
#remove the publish folder as we done need it #remove the publish folder as we done need it
if (-not (Test-Path "publish")) { if (-not (Test-Path "publish")) {
Write-Host "The publish folder is already deleted nothing else to do" Write-Host "The publish folder is already deleted nothing else to do"
@@ -133,6 +150,15 @@ function Update-BuildNumber {
dotnet publish -c Release -o ./publish dotnet publish -c Release -o ./publish
$webConfigPath = "web.config"
$content = Get-Content -Path $webConfigPath -Raw
$newContent = $content -replace '(?<=Rewrite" url="http://localhost:)\d+(?=/\{R:1\}")', "8080"
$newContent | Set-Content -Path $webConfigPath -NoNewline
Write-Host "Updated web.config rewrite port back to 8080"
Pop-Location Pop-Location
Write-Host "Building Docs" Write-Host "Building Docs"