| | | 1 | | |
| | | 2 | | <# |
| | | 3 | | .SYNOPSIS |
| | | 4 | | Resolves a Kestrun server instance from the provided input. |
| | | 5 | | |
| | | 6 | | .DESCRIPTION |
| | | 7 | | The Resolve-KestrunServer function checks if the provided server instance is valid. |
| | | 8 | | If not, it attempts to retrieve the default Kestrun server instance. |
| | | 9 | | |
| | | 10 | | .PARAMETER Server |
| | | 11 | | The Kestrun server instance to resolve. |
| | | 12 | | |
| | | 13 | | .EXAMPLE |
| | | 14 | | $resolvedServer = Resolve-KestrunServer -Server $myServer |
| | | 15 | | This will resolve $myServer to a valid Kestrun server instance. |
| | | 16 | | |
| | | 17 | | .NOTES |
| | | 18 | | If no server is provided, the function will look for the default Kestrun server instance |
| | | 19 | | managed by KestrunHostManager. If no default instance exists, an error is thrown. |
| | | 20 | | Used inside kestrun cmdlets to ensure a valid server instance is available for operations |
| | | 21 | | as: $Server = Resolve-KestrunServer -Server $Server |
| | | 22 | | #> |
| | | 23 | | function Resolve-KestrunServer { |
| | | 24 | | param ( |
| | | 25 | | [Kestrun.Hosting.KestrunHost]$Server |
| | | 26 | | ) |
| | 0 | 27 | | if ($null -eq $Server) { |
| | 0 | 28 | | if ($null -ne $KrServer) { |
| | 0 | 29 | | Write-KrLog -Level Verbose -Message "No server specified, using global `$KrServer variable." |
| | | 30 | | # If no server is specified, use the global $KrServer variable |
| | | 31 | | # This is useful for scripts that run in the context of a Kestrun server |
| | 0 | 32 | | $Server = $KrServer |
| | | 33 | | } else { |
| | | 34 | | # Try to get the default Kestrun server instance |
| | 0 | 35 | | $Server = [Kestrun.KestrunHostManager]::Default |
| | | 36 | | } |
| | 0 | 37 | | if ($null -eq $Server) { |
| | 0 | 38 | | throw 'No Kestrun server instance found. Please create a Kestrun server instance.' |
| | | 39 | | } |
| | | 40 | | } |
| | 0 | 41 | | return $Server |
| | | 42 | | } |
| | | 43 | | |