| | | 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 DocId |
| | | 11 | | The OpenAPI document IDs to which the SignalR hub endpoint should be added. Default is ' |
| | | 12 | | .PARAMETER Summary |
| | | 13 | | Optional OpenAPI summary override for the SignalR hub endpoint. |
| | | 14 | | .PARAMETER Description |
| | | 15 | | Optional OpenAPI description override for the SignalR hub endpoint. |
| | | 16 | | .PARAMETER Tags |
| | | 17 | | Optional OpenAPI tags override for the SignalR hub endpoint. |
| | | 18 | | .PARAMETER HubName |
| | | 19 | | Optional name of the SignalR hub. If not provided, defaults to 'kestrun'. |
| | | 20 | | .PARAMETER IncludeNegotiateEndpoint |
| | | 21 | | If specified, includes the negotiate endpoint for the SignalR hub. |
| | | 22 | | .PARAMETER SkipOpenApi |
| | | 23 | | If specified, the OpenAPI documentation for this endpoint will be skipped. |
| | | 24 | | .PARAMETER Options |
| | | 25 | | Full OpenAPI customization object (Kestrun.Hosting.Options.SignalROpenApiOptions). |
| | | 26 | | When provided, it takes precedence over the individual -OpenApi* parameters. |
| | | 27 | | .PARAMETER PassThru |
| | | 28 | | If specified, the cmdlet will return the modified server instance after adding the SignalR hub. |
| | | 29 | | .EXAMPLE |
| | | 30 | | Add-KrSignalRHubMiddleware -Path '/hubs/notifications' -PassThru |
| | | 31 | | Adds a SignalR hub at the path '/hubs/notifications' and returns the modified server instance. |
| | | 32 | | .NOTES |
| | | 33 | | This function is part of the Kestrun PowerShell module and is used to manage SignalR hubs on the Kestrun server. |
| | | 34 | | The Server parameter accepts a KestrunHost instance; if not provided, the default server is used. |
| | | 35 | | The Path parameter specifies the URL path where the SignalR hub will be accessible. |
| | | 36 | | The PassThru switch allows the function to return the modified server instance for further use. |
| | | 37 | | #> |
| | | 38 | | function Add-KrSignalRHubMiddleware { |
| | | 39 | | [KestrunRuntimeApi('Definition')] |
| | | 40 | | [CmdletBinding(DefaultParameterSetName = 'Items')] |
| | | 41 | | param( |
| | | 42 | | [Parameter(ValueFromPipeline)] |
| | | 43 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 44 | | |
| | | 45 | | [Parameter(Mandatory = $false, ParameterSetName = 'Items')] |
| | | 46 | | [Parameter(Mandatory = $false, ParameterSetName = 'ItemsSkipOpenApi')] |
| | | 47 | | [string]$Path, |
| | | 48 | | |
| | | 49 | | [Parameter(Mandatory = $false, ParameterSetName = 'Items')] |
| | | 50 | | [Parameter(Mandatory = $false, ParameterSetName = 'ItemsSkipOpenApi')] |
| | | 51 | | [string[]]$DocId = [Kestrun.OpenApi.OpenApiDocDescriptor]::DefaultDocumentationIds, |
| | | 52 | | |
| | | 53 | | [Parameter(Mandatory = $false, ParameterSetName = 'Items')] |
| | | 54 | | [string]$Summary, |
| | | 55 | | |
| | | 56 | | [Parameter(Mandatory = $false, ParameterSetName = 'Items')] |
| | | 57 | | [string]$Description, |
| | | 58 | | |
| | | 59 | | [Parameter(Mandatory = $false, ParameterSetName = 'Items')] |
| | | 60 | | [string[]]$Tags, |
| | | 61 | | |
| | | 62 | | [Parameter(Mandatory = $false, ParameterSetName = 'Items')] |
| | | 63 | | [string]$HubName, |
| | | 64 | | |
| | | 65 | | [Parameter(Mandatory = $false, ParameterSetName = 'ItemsSkipOpenApi')] |
| | | 66 | | [switch]$SkipOpenApi, |
| | | 67 | | |
| | | 68 | | [Parameter(Mandatory = $false, ParameterSetName = 'Items')] |
| | | 69 | | [switch]$IncludeNegotiateEndpoint, |
| | | 70 | | |
| | | 71 | | [Parameter(Mandatory = $true, ParameterSetName = 'Options')] |
| | | 72 | | [Kestrun.Hosting.Options.SignalROptions]$Options, |
| | | 73 | | |
| | | 74 | | [Parameter()] |
| | | 75 | | [switch]$PassThru |
| | | 76 | | ) |
| | | 77 | | begin { |
| | | 78 | | # Ensure the server instance is resolved |
| | 0 | 79 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 80 | | } |
| | | 81 | | process { |
| | | 82 | | |
| | 0 | 83 | | if ($PSCmdlet.ParameterSetName -eq 'Items') { |
| | 0 | 84 | | $Options = [Kestrun.Hosting.Options.SignalROptions]::new() |
| | 0 | 85 | | if ( $SkipOpenApi.IsPresent ) { |
| | 0 | 86 | | $Options.SkipOpenApi = $true |
| | | 87 | | } |
| | | 88 | | |
| | 0 | 89 | | if ($PSBoundParameters.ContainsKey('Summary')) { $Options.Summary = $Summary } |
| | 0 | 90 | | if ($PSBoundParameters.ContainsKey('Description')) { $Options.Description = $Description } |
| | 0 | 91 | | if ($PSBoundParameters.ContainsKey('Tags')) { $Options.Tags = $Tags } |
| | 0 | 92 | | if ($PSBoundParameters.ContainsKey('HubName')) { $Options.HubName = $HubName } |
| | | 93 | | # Set the documentation IDs for the SignalR hub |
| | 0 | 94 | | $Options.DocId = $DocId |
| | | 95 | | # Set the path for the SignalR hub |
| | 0 | 96 | | if ($PSBoundParameters.ContainsKey('Path')) { $Options.Path = $Path } |
| | 0 | 97 | | $Options.IncludeNegotiateEndpoint = $IncludeNegotiateEndpoint.IsPresent |
| | | 98 | | } |
| | 0 | 99 | | $server.AddSignalR($Options) | Out-Null |
| | | 100 | | |
| | 0 | 101 | | if ($PassThru.IsPresent) { |
| | | 102 | | # if the PassThru switch is specified, return the modified server instance |
| | 0 | 103 | | return $Server |
| | | 104 | | } |
| | | 105 | | } |
| | | 106 | | } |
| | | 107 | | |