< 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@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
0%
Covered lines: 0
Uncovered lines: 10
Coverable lines: 10
Total lines: 78
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

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 Authorization
 19        An optional array of authorization strings for the route.
 20
 21    .PARAMETER PassThru
 22        If specified, the function will return the created route object.
 23
 24    .OUTPUTS
 25        [Microsoft.AspNetCore.Builder.IEndpointConventionBuilder] representing the created route.
 26
 27    .EXAMPLE
 28        Add-KrHtmlTemplateRoute -Server $myServer -Path "/myroute" -HtmlTemplatePath "C:\Templates\mytemplate.html"
 29        Adds a new HTML template route to the specified Kestrun server with the given path and template file.
 30
 31    .EXAMPLE
 32        Get-KrServer | Add-KrHtmlTemplateRoute -Path "/myroute" -HtmlTemplatePath "C:\Templates\mytemplate.html" -PassTh
 33        Adds a new HTML template route to the current Kestrun server and returns the route object
 34    .NOTES
 35        This function is part of the Kestrun PowerShell module and is used to manage routes
 36#>
 37function Add-KrHtmlTemplateRoute {
 38    [KestrunRuntimeApi('Definition')]
 39    [CmdletBinding()]
 40    [OutputType([Kestrun.Hosting.KestrunHost])]
 41    param(
 42        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 43        [Kestrun.Hosting.KestrunHost]$Server,
 44
 45        [Parameter(Mandatory = $true)]
 46        [alias('Path')]
 47        [string]$Pattern,
 48
 49        [Parameter(Mandatory = $true)]
 50        [string]$HtmlTemplatePath,
 51
 52        [Parameter()]
 53        [string[]]$Authorization = $null,
 54
 55        [Parameter()]
 56        [switch]$PassThru
 57    )
 58    begin {
 59        # Ensure the server instance is resolved
 060        $Server = Resolve-KestrunServer -Server $Server
 061        if ($null -eq $Server) {
 062            throw 'Server is not initialized. Please ensure the server is configured before setting options.'
 63        }
 64    }
 65    process {
 66
 067        $options = [Kestrun.Hosting.Options.MapRouteOptions]::new()
 068        $options.HttpVerbs = [Kestrun.Utilities.HttpVerb[]]::new([Kestrun.Utilities.HttpVerb]::Get)
 069        $options.Pattern = $Pattern
 070        $options.RequireAuthorization = $Authorization
 71
 072        [Kestrun.Hosting.KestrunHostMapExtensions]::AddHtmlTemplateRoute($Server, $options, $HtmlTemplatePath) | Out-Nul
 073        if ($PassThru) {
 074            return $Server
 75        }
 76    }
 77}
 78

Methods/Properties

Add-KrHtmlTemplateRoute()