| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Adds Razor Pages service to the server. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This cmdlet allows you to register Razor Pages with the Kestrun server. |
| | | 6 | | It can be used to serve dynamic web pages using Razor syntax. |
| | | 7 | | .PARAMETER Server |
| | | 8 | | The Kestrun server instance to which the Razor Pages service will be added. |
| | | 9 | | .PARAMETER Options |
| | | 10 | | The RazorPagesOptions to configure the Razor Pages service. |
| | | 11 | | .PARAMETER RootDirectory |
| | | 12 | | The root directory for the Razor Pages. |
| | | 13 | | .PARAMETER Conventions |
| | | 14 | | An array of page conventions to apply to the Razor Pages. |
| | | 15 | | .PARAMETER PassThru |
| | | 16 | | If specified, the cmdlet will return the modified server instance. |
| | | 17 | | .EXAMPLE |
| | | 18 | | $server | Add-KrRazorPageService -RootDirectory '/Pages' -Conventions $conventions |
| | | 19 | | This example adds Razor Pages service to the server, specifying the root directory and conventions for the pages |
| | | 20 | | .EXAMPLE |
| | | 21 | | $server | Add-KrRazorPageService -Options $options |
| | | 22 | | This example adds Razor Pages service to the server using the specified RazorPagesOptions. |
| | | 23 | | .LINK |
| | | 24 | | https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.razorpages.razorpagesoptions?view=aspnetco |
| | | 25 | | .NOTES |
| | | 26 | | This cmdlet is used to register Razor Pages with the Kestrun server, allowing you to serve dynamic web pages usi |
| | | 27 | | #> |
| | | 28 | | function Add-KrRazorPageService { |
| | | 29 | | [KestrunRuntimeApi('Definition')] |
| | | 30 | | [CmdletBinding(defaultParameterSetName = 'Items')] |
| | | 31 | | [OutputType([Kestrun.Hosting.KestrunHost])] |
| | | 32 | | param( |
| | | 33 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 34 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 35 | | |
| | | 36 | | [Parameter(Mandatory = $true, ParameterSetName = 'Options')] |
| | | 37 | | [Microsoft.AspNetCore.Mvc.RazorPages.RazorPagesOptions]$Options, |
| | | 38 | | |
| | | 39 | | [Parameter(ParameterSetName = 'Items')] |
| | | 40 | | [string]$RootDirectory, |
| | | 41 | | |
| | | 42 | | [Parameter(ParameterSetName = 'Items')] |
| | | 43 | | [Microsoft.AspNetCore.Mvc.ApplicationModels.IPageConvention[]]$Conventions = @(), |
| | | 44 | | |
| | | 45 | | [Parameter()] |
| | | 46 | | [switch]$PassThru |
| | | 47 | | ) |
| | | 48 | | begin { |
| | | 49 | | # Ensure the server instance is resolved |
| | 0 | 50 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 51 | | } |
| | | 52 | | process { |
| | 0 | 53 | | if ($PSCmdlet.ParameterSetName -eq 'Items') { |
| | 0 | 54 | | $Options = [Microsoft.AspNetCore.Mvc.RazorPages.RazorPagesOptions]::new() |
| | 0 | 55 | | if (-not [string]::IsNullOrWhiteSpace($RootDirectory)) { |
| | 0 | 56 | | $Options.RootDirectory = $RootDirectory |
| | | 57 | | } |
| | 0 | 58 | | if ($Conventions.Count -gt 0) { |
| | 0 | 59 | | foreach ($c in $Conventions) { |
| | 0 | 60 | | $Options.Conventions.Add($c) |
| | | 61 | | } |
| | | 62 | | } |
| | | 63 | | } |
| | | 64 | | |
| | 0 | 65 | | [Kestrun.Hosting.KestrunHostRazorExtensions]::AddRazorPages($Server, $Options) | Out-Null |
| | | 66 | | |
| | 0 | 67 | | if ($PassThru.IsPresent) { |
| | | 68 | | # if the PassThru switch is specified, return the modified server instance |
| | 0 | 69 | | return $Server |
| | | 70 | | } |
| | | 71 | | } |
| | | 72 | | } |
| | | 73 | | |