| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Maps a SignalR hub class to the given URL path. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function allows you to map a SignalR hub class to a specific URL path on the Kestrun server. |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun server instance to which the SignalR hub will be added. |
| | | 8 | | .PARAMETER Path |
| | | 9 | | The URL path where the SignalR hub will be accessible. Defaults to '/hubs/kestrun'. |
| | | 10 | | .PARAMETER PassThru |
| | | 11 | | If specified, the cmdlet will return the modified server instance after adding the SignalR hub. |
| | | 12 | | .EXAMPLE |
| | | 13 | | Add-KrSignalRHubMiddleware -Path '/hubs/notifications' -PassThru |
| | | 14 | | Adds a SignalR hub at the path '/hubs/notifications' and returns the modified server instance. |
| | | 15 | | .NOTES |
| | | 16 | | This function is part of the Kestrun PowerShell module and is used to manage SignalR hubs on the Kestrun server. |
| | | 17 | | The Server parameter accepts a KestrunHost instance; if not provided, the default server is used. |
| | | 18 | | The Path parameter specifies the URL path where the SignalR hub will be accessible. |
| | | 19 | | The PassThru switch allows the function to return the modified server instance for further use. |
| | | 20 | | #> |
| | | 21 | | function Add-KrSignalRHubMiddleware { |
| | | 22 | | [KestrunRuntimeApi('Definition')] |
| | | 23 | | [CmdletBinding()] |
| | | 24 | | param( |
| | | 25 | | [Parameter(ValueFromPipeline)] |
| | | 26 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 27 | | |
| | | 28 | | [Parameter(Mandatory = $false)] |
| | | 29 | | [string]$Path = '/hubs/kestrun', |
| | | 30 | | |
| | | 31 | | [Parameter()] |
| | | 32 | | [switch]$PassThru |
| | | 33 | | ) |
| | | 34 | | begin { |
| | | 35 | | # Ensure the server instance is resolved |
| | 0 | 36 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 37 | | } |
| | | 38 | | process { |
| | | 39 | | |
| | 0 | 40 | | $server.AddSignalR($Path) | Out-Null |
| | | 41 | | |
| | 0 | 42 | | if ($PassThru.IsPresent) { |
| | | 43 | | # if the PassThru switch is specified, return the modified server instance |
| | 0 | 44 | | return $Server |
| | | 45 | | } |
| | | 46 | | } |
| | | 47 | | } |
| | | 48 | | |