Pode.Web
Pode.Web copied to clipboard
Build pode web pages dynamically
Hi @Badgerati I once experimented a bit to build web pages only after a "click". This has many advantages especially for troubleshooting, because you can change the page source text without having to restart Pode.
Add-PodeWebPage -Name 'Test' -ScriptBlock {
Write-PodeHost "Build Site"
. $PSScriptRoot\mypage\\ndex.ps1
}
#....
New-PodeWebButton -Name Settings -DisplayName "Settings" -Icon check-decagram -ScriptBlock {
Write-PodeHost "Settings"
} #-Force
But now there is the problem that the routes already exist when, for example, a button is newly created with script. I solved this experimentally with a "Force" switch in the New-PodeWebButton CmdLet and then deleted the route there.
<# Change Button 20221025 #>
if($Force -and (Test-PodeWebRoute -Path $routePath)) {
#Write-PodeHost "Remove Route $routePath" -ForegroundColor Yellow
Remove-PodeWebRoute -Path $routePath -Method Post -EndpointName $EndpointName
}
Would that be enough or is there other data to delete? Would you want to have pull requests for this function (delete route with a force switch) and include that in the base source code?
Hi @AndreasNick,
The Route should be the only object that needs cleaning up.
I'm actually wondering if putting a -Force on Pode's Add-PodeRoute might be a cleaner approach - to prevent Pode.Web having loads and loads if (force) { remove-route } 😂.
Then we can add a -Force to required elements/layouts in Pode.Web, and pass this through to Test-PodeWebRoute and Add-PodeRoute 😄
Hi @Badgerati, I can put that in and try my hand at a pull request sometime. Furthermore I have a test Remove-PodeWebPage function in the code. This is perhaps also interesting for others? I would integrate some similar functions in my fork, because I want to know if you can use an add-on system with Pode.web. So install and delete web components. A "Remove-PodeRoute" is still missing here and it would also have to search for other routes to delete for the web pages:
function Remove-PodeWebPage{
param (
[Parameter(Mandatory=$true)]
[string]
$Name
)
$routePath = (Get-PodeWebPagePath -Name $Name -NoAppPath)
$pages = Get-PodeWebState -Name 'pages'
#$pages[$routePath] = $pageMeta
$pages[$routePath] = $Null
}
I'll do some more testing here :-)
Hi @AndreasNick,
A Remove-PodeWebPage is something I can see being useful! The function would need to take the -Name as well as -Group, and could then follow a flow something like:
- An initial test for the page via
Test-PodeWebPage(like used at the ofAdd-PodeWebPage) - Generate the
$routePathand get the page fromGet-PodeWebState - Call
Remove-PodeRouteon the$routePath - Call
Remove-PodeRouteon$($routePath)/help - Remove the
$routePathkey from the pages list returned fromGet-PodeWebState
^ that should cover removing everything for a page :)
There's also the possibility of adding a Remove-PodeWebPageLink as well. It looks like it would be identical to Remove-PodeWebPage though, so could just make it call that under-the-hood, haha