Skip to content

Instantly share code, notes, and snippets.

@ChendrayanV
Created November 19, 2021 13:28
Show Gist options
  • Save ChendrayanV/6dae43853d08ecb4626a98d6cf4c0bf2 to your computer and use it in GitHub Desktop.
Save ChendrayanV/6dae43853d08ecb4626a98d6cf4c0bf2 to your computer and use it in GitHub Desktop.
Pode - Web Server
Start-PodeServer {
Add-PodeEndpoint -Address * -Port 3000 -Protocol Http
Set-PodeViewEngine -Type PSHTML -Extension PS1 -ScriptBlock {
param($path, $data)
return (. $path $data)
}
Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
Write-PodeViewResponse -Path 'index.ps1'
}
Add-PodeRoute -Method Post -Path '/cost-estimation' -ScriptBlock {
$FileName = $($WebEvent.data['template'])
$Data = $([System.Text.Encoding]::UTF8.GetString($($WebEvent.Files."$FileName".Bytes))) | ConvertFrom-Json
if ($Data.resources.type -eq 'Microsoft.Storage/storageAccounts') {
$SkuName = $Data.resources.sku.name -replace '_' , ' '
$Result = Invoke-RestMethod -Uri "https://prices.azure.com/api/retail/prices?`$filter=serviceName eq 'Storage' and armRegionName eq 'centralindia' and skuName eq '$($SkuName)'"
$Result
Write-PodeJsonResponse -Value $($Result)
}
}
Add-PodeRoute -Method Get -Path '/home' -ScriptBlock {
Write-PodeViewResponse -Path 'home.ps1'
}
}
param($data)
return html -Content {
head -Content {
Title -Content "Reactor | Home"
Link -href "https://cdn.metroui.org.ua/v4.3.2/css/metro-all.min.css" -rel "stylesheet"
script -src "https://cdn.metroui.org.ua/v4/js/metro.min.js"
}
body -Content {
# Menu Bar
Div -Class "container bg-cyan fg-white pos-fixed fixed-top z-top" -Content {
header -Class "app-bar container bg-cyan fg-white pos-relative" `
-Attributes @{'data-role' = 'appbar'; 'data-expand-point' = 'md' } -Content {
a -href "#" -Class "brand fg-white no-hover" -Content "REACTOR" -Target "_blank"
ul -Class "app-bar-menu ml-auto" -Content {
li -Content { a -href "/about" -Content "About" }
li -Content { a -href "/dashboard" -Content "Dashboard" }
li -Content { a -href "/contact" -Content "Contact" }
}
}
}
(1..3).ForEach({ br })
Div -Class 'container' -Content {
form -action "/cost-estimation" -method "post" -enctype 'multipart/form-data' -content {
div -class 'form-group' -content {
label -content 'Template'
input -type 'file' -name 'template' -Attributes @{'data-role' = 'file' }
}
div -class 'form-group' -content {
button -class 'button bg-blue outline rounded' -content 'Login'
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment