forked from Badgerati/Pode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb-static.ps1
37 lines (28 loc) · 1.16 KB
/
web-static.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
param (
[int]
$Port = 8085
)
$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 server, and start listening on port 8085
Start-PodeServer -Threads 2 {
# listen on localhost:8085
Add-PodeEndpoint -Address * -Port $port -Protocol Http
New-PodeLoggingMethod -Terminal | Enable-PodeRequestLogging
New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging
# set view engine to pode renderer
Set-PodeViewEngine -Type Pode
# STATIC asset folder route
Add-PodeStaticRoute -Path '/assets' -Source './assets' -Defaults @('index.html')
Add-PodeStaticRoute -Path '/assets/download' -Source './assets' -DownloadOnly
# GET request for web page on "localhost:8085/"
Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
Write-PodeViewResponse -Path 'web-static' -Data @{ 'numbers' = @(1, 2, 3); }
}
# GET request to download a file from static route
Add-PodeRoute -Method Get -Path '/download' -ScriptBlock {
Set-PodeResponseAttachment -Path '/assets/images/Fry.png'
}
}