diff --git a/.env-example b/.env-example index 96f336c..9b5b6e9 100644 --- a/.env-example +++ b/.env-example @@ -1,6 +1,9 @@ # uncomment this out to run in productions # APP_ENV=production +# Server port that will allow vite to talk to the backend. +VITE_SERVER_PORT=4000 + # lstv2 loc LSTV2="C\drive\loc" diff --git a/backend/main.go b/backend/main.go index 225aac1..26c2f71 100644 --- a/backend/main.go +++ b/backend/main.go @@ -25,6 +25,7 @@ import ( "github.com/gin-gonic/gin" "github.com/joho/godotenv" "lst.net/cmd/services/logging" + "lst.net/cmd/services/system/config" _ "lst.net/docs" "lst.net/utils/db" ) @@ -110,10 +111,16 @@ func main() { }) logging.RegisterLoggerRoutes(r, basePath) + config.RegisterConfigRoutes(r, basePath) 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) { diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 74484b4..c56c92c 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -94,9 +94,10 @@ function Update-BuildNumber { Push-Location $rootDir/backend + Write-Host "Building the app" 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 if ($LASTEXITCODE -ne 0) { Write-Warning "app build failed!" @@ -124,6 +125,22 @@ function Update-BuildNumber { Write-Host "Building wrapper" 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 if (-not (Test-Path "publish")) { 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 + $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 Write-Host "Building Docs"