Skip to content

Commit 62c4582

Browse files
author
James Brundage
committed
fix: Start-Htmx ( Fixes #7 )
There's no place like 127.0.0.1
1 parent a543017 commit 62c4582

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

Commands/Start-Htmx.ps1

+2-3
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ function Start-Htmx {
186186
while ($httpListener.IsListening) {
187187
try {
188188
# If the server has a lifespan, we will stop it after the lifespan has passed.
189-
if (
190-
$LifeSpan -is [timespan] -and
189+
if ($LifeSpan -is [timespan] -and
191190
$lifeSpan.TotalMilliseconds -and
192191
[DateTime]::Now -gt $ServerStartTime.Add($LifeSpan)
193192
) {
@@ -361,7 +360,7 @@ function Start-Htmx {
361360
} else {
362361
# If we are on Windows, we will use a random port between 4kb and 32kb.
363362
if (-not $port) { $port = $(Get-Random -Min 4kb -Max 32kb)}
364-
"http://localhost:$port/"
363+
"http://127.0.0.1:$port/"
365364
}
366365
} else {
367366
$ServerUrl

HtmxPS.tests.ps1

+7-18
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,13 @@ describe HtmxPS {
1212
}
1313

1414
context 'Start-Htmx and Stop-Htmx' {
15-
it "Will start and stop a small htmx server" {
16-
if (-not $env:GITHUB_WORKSPACE) {
17-
$startedLocalJob = Start-Htmx -Htmx (
18-
htmx button "Click Me" hx-on:click="alert('Thanks, I needed that!')"
19-
)
20-
Invoke-RestMethod -Uri $startedLocalJob.ServerUrl
21-
$startedLocalJob | Stop-Htmx
22-
$startedLocalJob | Remove-Job
23-
} elseif ($env:HOSTNAME) {
24-
$startedLocalJob = Start-Htmx -Htmx (
25-
htmx button "Click Me" hx-on:click="alert('Thanks, I needed that!')"
26-
) -ServerUrl "http://$env:HOSTNAME:$(Get-Random -Min 4kb -Max 32kb)"
27-
Invoke-RestMethod -Uri $startedLocalJob.ServerUrl
28-
$startedLocalJob | Stop-Htmx
29-
$startedLocalJob | Remove-Job
30-
} else {
31-
Write-Warning "This test cannot be run without a GitHub workflow that has a host name."
32-
}
15+
it "Will start and stop a small htmx server" {
16+
$startedLocalJob = Start-Htmx -Htmx (
17+
htmx button "Click Me" hx-on:click="alert('Thanks, I needed that!')"
18+
)
19+
Invoke-RestMethod -Uri $startedLocalJob.ServerUrl
20+
$startedLocalJob | Stop-Htmx
21+
$startedLocalJob | Remove-Job
3322
}
3423
}
3524
}

0 commit comments

Comments
 (0)