forked from Badgerati/Pode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb-hostname.ps1
41 lines (31 loc) · 1.37 KB
/
web-hostname.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
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 at pode.foo.com
# -- You will need to add "127.0.0.1 pode.foo.com" to your hosts file
Start-PodeServer -Threads 2 {
# listen on localhost:8085
Add-PodeEndpoint -Address pode3.foo.com -Port $Port -Protocol Http
Add-PodeEndpoint -Address pode2.foo.com -Port $Port -Protocol Http
Add-PodeEndpoint -Address 127.0.0.1 -Hostname pode.foo.com -Port $Port -Protocol Http
Add-PodeEndpoint -Hostname pode4.foo.com -Port $Port -Protocol Http -LookupHostname
# logging
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')
# 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'
}
}