< Summary - Kestrun — Combined Coverage

Information
Class: Public.Route.Add-KrHtmlTemplateRoute
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Route/Add-KrHtmlTemplateRoute.ps1
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 90
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 08/26/2025 - 01:25:22 Line coverage: 0% (0/8) Total lines: 72 Tag: Kestrun/Kestrun@07f821172e5dc3657f1be7e6818f18d6721cf38a09/04/2025 - 18:11:31 Line coverage: 0% (0/8) Total lines: 73 Tag: Kestrun/Kestrun@de99e24698289f3f61ac7b73e96092732ae12b0509/08/2025 - 20:34:03 Line coverage: 0% (0/10) Total lines: 78 Tag: Kestrun/Kestrun@3790ee5884494a7a2a829344a47743e0bf492e7210/13/2025 - 16:52:37 Line coverage: 0% (0/8) Total lines: 75 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e10/15/2025 - 21:27:26 Line coverage: 0% (0/14) Total lines: 90 Tag: Kestrun/Kestrun@c33ec02a85e4f8d6061aeaab5a5e8c3a8b665594

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Route/Add-KrHtmlTemplateRoute.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Adds a new HTML template route to the Kestrun server.
 4
 5    .DESCRIPTION
 6        This function allows you to add a new HTML template route to the Kestrun server by specifying the route path and
 7
 8    .PARAMETER Server
 9        The Kestrun server instance to which the route will be added.
 10        If not specified, the function will attempt to resolve the current server context.
 11
 12    .PARAMETER Pattern
 13        The URL path for the new route.
 14
 15    .PARAMETER HtmlTemplatePath
 16        The file path to the HTML template to be used for the route.
 17
 18    .PARAMETER AuthorizationSchema
 19        An optional array of authorization schemes for the route.
 20
 21    .PARAMETER AuthorizationPolicy
 22        An optional array of authorization policies for the route.
 23
 24    .PARAMETER PassThru
 25        If specified, the function will return the created route object.
 26
 27    .OUTPUTS
 28        [Microsoft.AspNetCore.Builder.IEndpointConventionBuilder] representing the created route.
 29
 30    .EXAMPLE
 31        Add-KrHtmlTemplateRoute -Server $myServer -Path "/myroute" -HtmlTemplatePath "C:\Templates\mytemplate.html"
 32        Adds a new HTML template route to the specified Kestrun server with the given path and template file.
 33
 34    .EXAMPLE
 35        Get-KrServer | Add-KrHtmlTemplateRoute -Path "/myroute" -HtmlTemplatePath "C:\Templates\mytemplate.html" -PassTh
 36        Adds a new HTML template route to the current Kestrun server and returns the route object
 37    .NOTES
 38        This function is part of the Kestrun PowerShell module and is used to manage routes
 39#>
 40function Add-KrHtmlTemplateRoute {
 41    [KestrunRuntimeApi('Definition')]
 42    [CmdletBinding()]
 43    [OutputType([Kestrun.Hosting.KestrunHost])]
 44    param(
 45        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 46        [Kestrun.Hosting.KestrunHost]$Server,
 47
 48        [Parameter(Mandatory = $true)]
 49        [alias('Path')]
 50        [string]$Pattern,
 51
 52        [Parameter(Mandatory = $true)]
 53        [string]$HtmlTemplatePath,
 54
 55        [Parameter()]
 56        [string[]]$AuthorizationSchema = $null,
 57
 58        [Parameter()]
 59        [string[]]$AuthorizationPolicy = $null,
 60
 61        [Parameter()]
 62        [switch]$PassThru
 63    )
 64    begin {
 65        # Ensure the server instance is resolved
 066        $Server = Resolve-KestrunServer -Server $Server
 67    }
 68    process {
 69
 070        $options = [Kestrun.Hosting.Options.MapRouteOptions]::new()
 071        $options.Pattern = $Pattern
 072        if ($null -ne $AuthorizationSchema) {
 073            $Options.RequireSchemes = $AuthorizationSchema
 74        }
 075        if ($null -ne $AuthorizationPolicy) {
 076            $Options.RequirePolicies = $AuthorizationPolicy
 77        }
 078        if ([string]::IsNullOrWhiteSpace($HtmlTemplatePath)) {
 079            throw 'HtmlTemplatePath cannot be null or empty.'
 80        }
 81        # Resolve the file path relative to the Kestrun root if necessary
 082        $resolvedPath = Resolve-KrPath -Path $HtmlTemplatePath -KestrunRoot -Test
 083        Write-KrLog -Level Verbose -Message "Resolved file path: $resolvedPath"
 84        # Call the C# extension method to add the HTML template route
 085        [Kestrun.Hosting.KestrunHostMapExtensions]::AddHtmlTemplateRoute($Server, $options, $resolvedPath) | Out-Null
 086        if ($PassThru) {
 087            return $Server
 88        }
 89    }
 90}

Methods/Properties

Add-KrHtmlTemplateRoute()