forked from Badgerati/Pode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb-tp-eps.ps1
36 lines (27 loc) · 1.06 KB
/
web-tp-eps.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
$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
Import-Module -Name EPS
# create a server, and start listening on port 8085
Start-PodeServer -Threads 2 {
# listen on localhost:8085
Add-PodeEndpoint -Address * -Port 8085 -Protocol Http
# log requests to the terminal
New-PodeLoggingMethod -Terminal | Enable-PodeRequestLogging
# set view engine to EPS renderer
Set-PodeViewEngine -Type EPS -ScriptBlock {
param($path, $data)
$template = Get-Content -Path $path -Raw -Force
if ($null -eq $data) {
return (Invoke-EpsTemplate -Template $template)
}
else {
return (Invoke-EpsTemplate -Template $template -Binding $data)
}
}
# GET request for web page on "localhost:8085/"
Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
Write-PodeViewResponse -Path 'index' -Data @{ 'numbers' = @(1, 2, 3); 'date' = [DateTime]::UtcNow; }
}
}