forked from Badgerati/Pode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlockables.ps1
41 lines (30 loc) · 1.34 KB
/
lockables.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
$path = Split-Path -Parent -Path (Split-Path -Parent -Path $MyInvocation.MyCommand.Path)
Import-Module "$($path)/src/Pode.psm1" -Force -ErrorAction Stop
# or just:
# Import-Module Pode
# create a basic server
Start-PodeServer -Threads 2 {
Add-PodeEndpoint -Address * -Port 8090 -Protocol Http
New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging
New-PodeLockable -Name 'TestLock'
Add-PodeRoute -Method Get -Path '/custom-route1' -ScriptBlock {
Get-PodeLockable -Name 'TestLock' | Lock-PodeObject -ScriptBlock {
Start-Sleep -Seconds 10
}
Write-PodeJsonResponse -Value @{ Route = 1; Thread = $ThreadId }
}
Add-PodeRoute -Method Get -Path '/custom-route2' -ScriptBlock {
Get-PodeLockable -Name 'TestLock' | Lock-PodeObject -ScriptBlock {}
Write-PodeJsonResponse -Value @{ Route = 2; Thread = $ThreadId }
}
Add-PodeRoute -Method Get -Path '/global-route1' -ScriptBlock {
Lock-PodeObject -ScriptBlock {
Start-Sleep -Seconds 10
}
Write-PodeJsonResponse -Value @{ Route = 1; Thread = $ThreadId }
}
Add-PodeRoute -Method Get -Path '/global-route2' -ScriptBlock {
Get-PodeLockable -Name 'TestLock' | Lock-PodeObject -CheckGlobal -ScriptBlock {}
Write-PodeJsonResponse -Value @{ Route = 2; Thread = $ThreadId }
}
}