| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Adds PowerShell support for Razor Pages. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This cmdlet allows you to register Razor Pages with PowerShell support in the Kestrun server. |
| | | 6 | | It can be used to serve dynamic web pages using Razor syntax with PowerShell code blocks. |
| | | 7 | | .PARAMETER Server |
| | | 8 | | The Kestrun server instance to which the PowerShell Razor Pages service will be added. |
| | | 9 | | .PARAMETER RootPath |
| | | 10 | | The root directory for the Razor Pages. If not specified, the default 'Pages' directory under the content root will |
| | | 11 | | .PARAMETER PathPrefix |
| | | 12 | | An optional path prefix for the Razor Pages. If specified, the Razor Pages will be served under this path. |
| | | 13 | | .PARAMETER PassThru |
| | | 14 | | If specified, the cmdlet will return the modified server instance. |
| | | 15 | | .EXAMPLE |
| | | 16 | | $server | Add-KrPowerShellRazorPagesRuntime -PathPrefix '/pages' |
| | | 17 | | This example adds PowerShell support for Razor Pages to the server, with a path prefix of '/pages'. |
| | | 18 | | .EXAMPLE |
| | | 19 | | $server | Add-KrPowerShellRazorPagesRuntime |
| | | 20 | | This example adds PowerShell support for Razor Pages to the server without a path prefix. |
| | | 21 | | .NOTES |
| | | 22 | | This cmdlet is used to register Razor Pages with PowerShell support in the Kestrun server, allowing you to serve dyn |
| | | 23 | | #> |
| | | 24 | | function Add-KrPowerShellRazorPagesRuntime { |
| | | 25 | | [KestrunRuntimeApi('Definition')] |
| | | 26 | | [CmdletBinding()] |
| | | 27 | | [OutputType([Kestrun.Hosting.KestrunHost])] |
| | | 28 | | param( |
| | | 29 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 30 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 31 | | |
| | | 32 | | [Parameter()] |
| | | 33 | | [string]$RootPath = $null, |
| | | 34 | | |
| | | 35 | | [Parameter()] |
| | | 36 | | [string]$PathPrefix = $null, |
| | | 37 | | |
| | | 38 | | [Parameter()] |
| | | 39 | | [switch]$PassThru |
| | | 40 | | ) |
| | | 41 | | begin { |
| | | 42 | | # Ensure the server instance is resolved |
| | 0 | 43 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 44 | | } |
| | | 45 | | process { |
| | 0 | 46 | | if (-not ([string]::IsNullOrEmpty($RootPath))) { |
| | 0 | 47 | | $RootPath = (Resolve-KrPath -Path $RootPath) |
| | | 48 | | } |
| | | 49 | | # Add PowerShell support for Razor Pages with a path prefix |
| | 0 | 50 | | $Server.AddPowerShellRazorPages($RootPath, $PathPrefix) | Out-Null |
| | | 51 | | |
| | 0 | 52 | | if ($PassThru.IsPresent) { |
| | | 53 | | # if the PassThru switch is specified, return the modified server instance |
| | 0 | 54 | | return $Server |
| | | 55 | | } |
| | | 56 | | } |
| | | 57 | | } |
| | | 58 | | |