moved dispatch-request from line 1545 to global settings section
This commit is contained in:
@@ -335,6 +335,49 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Sends the HTML for a given page or invokes a task handler
|
||||||
|
function Dispatch-Request {
|
||||||
|
param($Context)
|
||||||
|
|
||||||
|
# figure out the path
|
||||||
|
$path = $Context.Request.Url.AbsolutePath.TrimStart('/')
|
||||||
|
|
||||||
|
# ---- Shutdown handler ----
|
||||||
|
if ($path -eq 'quit') {
|
||||||
|
Write-LogHybrid "Shutdown requested" "Info" "Server"
|
||||||
|
Respond-Text $Context "Server shutting down."
|
||||||
|
# stop the listener loop
|
||||||
|
$Global:Listener.Stop()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---- Fetch Sites endpoint ----
|
||||||
|
if ($Context.Request.HttpMethod -eq 'POST' -and $path -eq 'getpw') {
|
||||||
|
Handle-FetchSites $Context
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---- Serve UI pages ----
|
||||||
|
if ($path -in @('', 'onboard', 'offboard', 'tweaks', 'SVSApps')) {
|
||||||
|
$page = if ($path -eq '') { 'onboard' } else { $path }
|
||||||
|
$html = Get-UIHtml -Page $page
|
||||||
|
Respond-HTML $Context $html
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---- Task invocation ----
|
||||||
|
$task = $Global:Tasks | Where-Object Name -EQ $path
|
||||||
|
if ($task) {
|
||||||
|
& $task.HandlerFn $Context
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---- 404 ----
|
||||||
|
$Context.Response.StatusCode = 404
|
||||||
|
Respond-Text $Context '404 - Not Found'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion region globalsetting
|
#endregion region globalsetting
|
||||||
|
|
||||||
#region ScriptMonkey run silently Entrypoint
|
#region ScriptMonkey run silently Entrypoint
|
||||||
@@ -1542,47 +1585,6 @@ $script
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sends the HTML for a given page or invokes a task handler
|
|
||||||
function Dispatch-Request {
|
|
||||||
param($Context)
|
|
||||||
|
|
||||||
# figure out the path
|
|
||||||
$path = $Context.Request.Url.AbsolutePath.TrimStart('/')
|
|
||||||
|
|
||||||
# ---- Shutdown handler ----
|
|
||||||
if ($path -eq 'quit') {
|
|
||||||
Write-LogHybrid "Shutdown requested" "Info" "Server"
|
|
||||||
Respond-Text $Context "Server shutting down."
|
|
||||||
# stop the listener loop
|
|
||||||
$Global:Listener.Stop()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
# ---- Fetch Sites endpoint ----
|
|
||||||
if ($Context.Request.HttpMethod -eq 'POST' -and $path -eq 'getpw') {
|
|
||||||
Handle-FetchSites $Context
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
# ---- Serve UI pages ----
|
|
||||||
if ($path -in @('', 'onboard', 'offboard', 'tweaks', 'SVSApps')) {
|
|
||||||
$page = if ($path -eq '') { 'onboard' } else { $path }
|
|
||||||
$html = Get-UIHtml -Page $page
|
|
||||||
Respond-HTML $Context $html
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
# ---- Task invocation ----
|
|
||||||
$task = $Global:Tasks | Where-Object Name -EQ $path
|
|
||||||
if ($task) {
|
|
||||||
& $task.HandlerFn $Context
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
# ---- 404 ----
|
|
||||||
$Context.Response.StatusCode = 404
|
|
||||||
Respond-Text $Context '404 - Not Found'
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user