moved the start-server into the global seeting section
This commit is contained in:
@@ -311,6 +311,29 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Starts the HTTP listener loop
|
||||||
|
function Start-Server {
|
||||||
|
# make it accessible to Dispatch-Request
|
||||||
|
$Global:Listener = [System.Net.HttpListener]::new()
|
||||||
|
$Global:Listener.Prefixes.Add("http://localhost:$Port/")
|
||||||
|
$Global:Listener.Start()
|
||||||
|
Write-Host "Listening on http://localhost:$Port/ ..."
|
||||||
|
|
||||||
|
try {
|
||||||
|
while ($Global:Listener.IsListening) {
|
||||||
|
$ctx = $Global:Listener.GetContext()
|
||||||
|
try {
|
||||||
|
Dispatch-Request $ctx
|
||||||
|
} catch {
|
||||||
|
Write-LogHybrid "Dispatch error: $_" "Error" "Server"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
# once the loop exits, clean up
|
||||||
|
$Global:Listener.Close()
|
||||||
|
Write-LogHybrid "Listener closed." "Info" "Server"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion region globalsetting
|
#endregion region globalsetting
|
||||||
|
|
||||||
@@ -1561,32 +1584,6 @@ $script
|
|||||||
Respond-Text $Context '404 - Not Found'
|
Respond-Text $Context '404 - Not Found'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Starts the HTTP listener loop
|
|
||||||
function Start-Server {
|
|
||||||
# make it accessible to Dispatch-Request
|
|
||||||
$Global:Listener = [System.Net.HttpListener]::new()
|
|
||||||
$Global:Listener.Prefixes.Add("http://localhost:$Port/")
|
|
||||||
$Global:Listener.Start()
|
|
||||||
Write-Host "Listening on http://localhost:$Port/ ..."
|
|
||||||
|
|
||||||
try {
|
|
||||||
while ($Global:Listener.IsListening) {
|
|
||||||
$ctx = $Global:Listener.GetContext()
|
|
||||||
try {
|
|
||||||
Dispatch-Request $ctx
|
|
||||||
} catch {
|
|
||||||
Write-LogHybrid "Dispatch error: $_" "Error" "Server"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
# once the loop exits, clean up
|
|
||||||
$Global:Listener.Close()
|
|
||||||
Write-LogHybrid "Listener closed." "Info" "Server"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user