forked from Badgerati/Pode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb-pages-docker.ps1
47 lines (36 loc) · 1.43 KB
/
web-pages-docker.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Import-Module /usr/local/share/powershell/Modules/Pode/Pode.psm1 -Force -ErrorAction Stop
<#
docker-compose up --force-recreate --build
#>
# create a server, and start listening on port 8085
Start-PodeServer -Threads 2 {
# listen on *:8085
Add-PodeEndpoint -Address * -Port 8085 -Protocol Http
Set-PodeSecurity -Type Simple
# set view engine to pode renderer
Set-PodeViewEngine -Type Pode
Add-PodeTask -Name 'Test' -ScriptBlock {
'a string'
4
return @{ InnerValue = 'hey look, a value!' }
}
# GET request for web page on "localhost:8085/"
Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
Write-PodeViewResponse -Path 'simple' -Data @{ 'numbers' = @(1, 2, 3); }
}
# GET request throws fake "500" server error status code
Add-PodeRoute -Method Get -Path '/error' -ScriptBlock {
Set-PodeResponseStatus -Code 500
}
# PUT update a file to trigger monitor
Add-PodeRoute -Method Put -Path '/file' -ScriptBlock {
'Hello, world!' | Out-File -FilePath "$($PodeContext.Server.Root)/file.txt" -Append -Force
}
Add-PodeRoute -Method Get -Path '/user/:userId' -ScriptBlock {
Write-PodeJsonResponse -Value @{ UserId = $WebEvent.Parameters['userId'] }
}
Add-PodeRoute -Method Get -Path '/run-task' -ScriptBlock {
$result = Invoke-PodeTask -Name 'Test' -Wait
Write-PodeJsonResponse -Value @{ Result = $result }
}
}