Hey guys, random question here, just trying to figure out how others are managing a scenario where you have long, literally long coded endpoints (not long executing but 2-3 hundred lines), besides possible function conversion, is dot sourcing a thing here?
just split up in functions ?
From a readability perspective:
I put all my endpoints in separate files, to hide them from sight.
$Endpoints = Get-ChildItem (Join-Path $PSScriptRoot 'Endpoints') | ForEach-Object {
& $_.FullName
}
If you’re not talking about REST / Scheduled endpoints, but rather endpoints for grids… I usually just minimize them.
If you don’t want to this, you could always put them in a separate file, and dynamically load the content and convert it to scriptblock.
$scriptblock = (Get-Command %pathtofile%).ScriptBlock
Same thing, i have a lot of rest endpoints, and use separate files foreach endpoint.
I also use a folder structure that group endpoints by category … For example i have a “Route_User” where all user endpoints file are in… I Prefix each file with “UDRoute_*.ps1”
I have a build script that build a server.ps1 … then run it
So i can create new route (if i dont prefix them, they are not touched by the build script), without affecting others routes …
Thanks @BoSen29 and @LxLechat, I’m going to give that solution a shot, It would definitely be much cleaner to have a start script with out the endpoints, hopefully will have some cycles tonight…
I’ll post here to give an update.
@BoSen29, question, didnt have any luck with the example above, I get the collection of files, but for somereason the call operator isnt executing, on that same note how are the endpoints themselves added to $Endpoint, since there currently set as variables, ($endpointA, $endpointB…)
@dtnyc9005
Here is a full example of how you can do it
for this example am using 2 folders like below
endpoints
pages
in the endponits folder i have the end points ps1 files like this example
New-UDEndpoint -Endpoint {
//your code goes here//
} -Schedule (New-UDEndpointSchedule -Every 1 -Day)
under pages folder you have ps1 files like the following example
New-UDPage -Name "Home" -Icon home -DefaultHomePage -Content { //your code goes here }
the Dashboard.ps1 file at the root location where these tow folders located will look like this
Get-UDDashboard | Stop-UDDashboard
$Endpoints = Get-ChildItem (Join-Path $PSScriptRoot 'EndPoints') | ForEach-Object {
& $_.FullName
}
$Pages = Get-ChildItem (Join-Path $PSScriptRoot 'Pages') -Recurse -File | ForEach-Object {
& $_.FullName
}
Start-UDDashboard -Wait -Endpoint $Endpoints -Content{
New-UDDashboard -Pages $Pages -Title "Dashboard" -Color '#FF050F7F'
} -Port 80 -Name Dashboard
dont use ($endpointA, $endpointB…) when you create your endpoints .ps1 files just use new-udendpoint…etc in every file you create.
@wsl2001 this worked like a charm!!!, this approach is much cleaner than just having them all part of a kickstart script.
this was awesomeness thanks @wsl2001.
you are welcome