-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmws-routes.ps1
More file actions
83 lines (62 loc) · 2.58 KB
/
mws-routes.ps1
File metadata and controls
83 lines (62 loc) · 2.58 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
79
80
81
82
83
#
# Copyright (c) 2023 Konstantin Gorshkov (see https://github.com/rcilogic). All Rights Reserved
# This code is licensed under MIT license (see LICENSE.txt for details)
#
# Main route
$webServer.staticRoutes['/'] = @{
path = "./htdocs"
index = "index.html" # , "index.ps1"
# Guards. Guards are executed first. They can modify the response and also abort the request execution.
# Provide guard with a script block
# guard = { $request = @($input) ; ... }
# Provide guard with a script file ('.ps1'). Guard's can modify the response and also abort the request execution.
# guardFiles = './path/to/guard-file.ps1' # , './path/to/guard-file2.ps1'
# Enable script execution (only '.ps1' files are supported)
# executableScripts = $true
# Enable directory browsing if the index file is not found.
# directoryBrowse = $true
# If single ingex is enabled, all child route directories will reference the index file in the route's root directory.
# singleIndex = $false
# Disable response compression
# useCompression = $false
}
# -------------------- Examples -------------------- #
# Uncomment to enable example routes.
<#
# Static route:
$webServer.staticRoutes['/examples'] = @{
path = "./examples/htdocs"
useCompression = $true
executableScripts = $true
directoryBrowse = $true
index = "index.html", "index.ps1"
singleIndex = $false
}
# Static route with a guard file:
$webServer.staticRoutes['/examples/secured-by-guard/'] = @{
path = "./examples/htdocs/secured-by-guard/"
guardFiles = './examples/guards/guard-example.ps1'
directoryBrowse = $true
}
# Static route with single index:
$webServer.staticRoutes['/examples/single-index'] = @{
path = "./examples/htdocs/single-index/"
index = "index.html", "index.ps1"
singleIndex = $true
executableScripts = $true
}
# Scripted route with parameters
$webServer.routes['get /examples/greet/:name'] = { $request = @($input)[0]
$name = $request.params['name']
"Hello, $name!"
}
# Scripted route with a guard
$webServer.routes['get /examples/context-info'] = { $request = @($input)[0]
# Apply the guard file
if (-not $request.guardCheck('./examples/guards/guard-example.ps1')) { return }
# Set a custom MIME type. You can also use 'text/json' instead of the preloaded server MIME types.
$request.mimeType = $request.server.mimeTypes['.json']
# Return context in JSON format
$request.context | ConvertTo-Json -Depth 3
}
#>