| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Adds a Unix socket listener to a Kestrun server instance. |
| | 4 | | .DESCRIPTION |
| | 5 | | This function adds a Unix socket listener to the specified Kestrun server instance, allowing it to listen for incomi |
| | 6 | | .PARAMETER Server |
| | 7 | | The Kestrun server instance to which the Unix socket listener will be added. This parameter is optional and can be p |
| | 8 | | .PARAMETER SocketPath |
| | 9 | | The path of the Unix domain socket on which the server will listen for incoming requests. This parameter is mandator |
| | 10 | | .PARAMETER PassThru |
| | 11 | | If specified, the cmdlet will return the modified server instance after adding the Unix socket listener |
| | 12 | | .EXAMPLE |
| | 13 | | Add-KrListenUnixSocket -Server $server -SocketPath "/tmp/mysocket" |
| | 14 | | Adds a Unix socket listener with the specified path to the given Kestrun server instance. |
| | 15 | | .NOTES |
| | 16 | | This function is designed to be used in the context of a Kestrun server setup and allows for flexible configuration |
| | 17 | | The Unix socket listener will be added to the server's options and will be used when the server is started to listen |
| | 18 | | #> |
| | 19 | | function Add-KrListenUnixSocket { |
| | 20 | | [KestrunRuntimeApi('Definition')] |
| | 21 | | [CmdletBinding(defaultParameterSetName = 'NoCert')] |
| | 22 | | [OutputType([Kestrun.Hosting.KestrunHost])] |
| | 23 | | param( |
| | 24 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | 25 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | 26 | |
|
| | 27 | | [Parameter(Mandatory = $true)] |
| | 28 | | [string]$SocketPath, |
| | 29 | |
|
| | 30 | | [Parameter()] |
| | 31 | | [switch]$PassThru |
| | 32 | | ) |
| | 33 | | begin { |
| 0 | 34 | | if (-not $IsWindows) { |
| 0 | 35 | | Write-Warning 'This function is for Windows Operating Systems only, as named pipes are not supported nativel |
| | 36 | | } |
| | 37 | | # Ensure the server instance is resolved |
| 0 | 38 | | $Server = Resolve-KestrunServer -Server $Server |
| 0 | 39 | | if ($null -eq $Server) { |
| 0 | 40 | | throw 'Server is not initialized. Please ensure the server is configured before setting options.' |
| | 41 | | } |
| | 42 | | } |
| | 43 | | process { |
| | 44 | | # Add the Unix socket listener to the server options |
| 0 | 45 | | $Server.Options.ListenUnixSockets.Add($SocketPath) |
| | 46 | |
|
| 0 | 47 | | if ($PassThru.IsPresent) { |
| | 48 | | # Return the modified server instance |
| 0 | 49 | | return $Server |
| | 50 | | } |
| | 51 | | } |
| | 52 | | } |
| | 53 | |
|