-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathRoutes.ps1
More file actions
78 lines (68 loc) · 1.7 KB
/
Routes.ps1
File metadata and controls
78 lines (68 loc) · 1.7 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
$Routes = @(
@{
'RequestType' = 'GET'
'RequestURL' = '/index'
'RedirectURL' = '/index.html'
}
@{
'RequestType' = 'GET'
'RequestURL' = ''
'RedirectURL' = '/index.html'
}
@{
'RequestType' = 'GET'
'RequestURL' = '/'
'RedirectURL' = '/index.html'
}
# Example of a route that contains a custom scriptblock
@{
'RequestType' = 'GET'
'RequestURL' = '/process'
'ScriptBlock' = {
Get-Process
}
}
# Example of a more web-friendly route with scriptblock
@{
'RequestType' = 'GET'
'RequestURL' = '/getservice'
'ScriptBlock' = {
Get-Service | ConvertTo-Html
}
}
# Get-Process piped to ConvertTo-Html will generate a table with all process data, so it is better to filter it before output
@{
'RequestType' = 'GET'
'RequestURL' = '/getprocess'
'ScriptBlock' = {
Get-Process | select Name, Id, CPU, WorkingSet, Path | ConvertTo-Html
}
}
# Example of try .. catch block
@{
'RequestType' = 'GET'
'RequestURL' = '/getfail'
'ScriptBlock' = {
try {
Get-ChildItem c:\..\.. | ConvertTo-Html
}
catch {
$Error[0] | ConvertTo-Html -as List
}
}
}
# ... Why not?
@{
'RequestType' = 'GET'
'RequestURL' = '/reloadroutes'
'ScriptBlock' = {
try {
. $Root\Routes.ps1
ConvertTo-Html -Body 'Reload is complete.'
}
catch {
$Error[0] | ConvertTo-Html -as List
}
}
}
)