Skip to content
Open
76 changes: 60 additions & 16 deletions src/Public/Routes.ps1
Comment thread
eltyBelgium marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -1106,17 +1106,23 @@ An Array of strings representing the unique tag for the API specification.
This tag helps in distinguishing between different versions or types of API specifications within the application.
You can use this tag to reference the specific API documentation, schema, or version that your function interacts with.

.PARAMETER FilePath
A literal, or relative, path to a file containing a ScriptBlock for the Route's main logic.

.EXAMPLE
Add-PodeRouteGroup -Path '/api' -Routes { Add-PodeRoute -Path '/route1' -Etc }

.EXAMPLE
Add-PodeRouteGroup -Path '/api' -FilePath '/routes/file.ps1'
#>
function Add-PodeRouteGroup {
[CmdletBinding()]
[CmdletBinding(DefaultParameterSetName = 'Routes')]
param(
[Parameter()]
[string]
$Path,

[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true, ParameterSetName = 'Routes')]
[scriptblock]
$Routes,

Expand Down Expand Up @@ -1175,12 +1181,23 @@ function Add-PodeRouteGroup {
$AllowAnon,

[string[]]
$OADefinitionTag
$OADefinitionTag,

[Parameter(Mandatory = $true, ParameterSetName = 'File')]
[string]
$FilePath
)



if (Test-PodeIsEmpty $Routes) {
# The Route parameter needs a valid, not empty, scriptblock
throw ($PodeLocale.routeParameterNeedsValidScriptblockExceptionMessage)
if ($PSCmdlet.ParameterSetName -ieq 'File') {
$Routes = Convert-PodeFileToScriptBlock -FilePath $FilePath
}
else {
# The Route parameter needs a valid, not empty, scriptblock
throw ($PodeLocale.routeParameterNeedsValidScriptblockExceptionMessage)
}
}

if ($Path -eq '/') {
Expand Down Expand Up @@ -1352,9 +1369,12 @@ If supplied, the user will be redirected to the default page if found instead of

.EXAMPLE
Add-PodeStaticRouteGroup -Path '/static' -Routes { Add-PodeStaticRoute -Path '/images' -Etc }

.EXAMPLE
Add-PodeStaticRouteGroup -Path '/static' -FilePath '/routes/file.ps1'
#>
function Add-PodeStaticRouteGroup {
[CmdletBinding()]
[CmdletBinding(DefaultParameterSetName = 'Routes')]
param(
[Parameter()]
[string]
Expand All @@ -1364,7 +1384,7 @@ function Add-PodeStaticRouteGroup {
[string]
$Source,

[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true, ParameterSetName = 'Routes')]
[scriptblock]
$Routes,

Expand Down Expand Up @@ -1433,12 +1453,21 @@ function Add-PodeStaticRouteGroup {
$DownloadOnly,

[switch]
$RedirectToDefault
$RedirectToDefault,

[Parameter(Mandatory = $true, ParameterSetName = 'File')]
[string]
$FilePath
Comment thread
eltyBelgium marked this conversation as resolved.
)

if (Test-PodeIsEmpty $Routes) {
# The Route parameter needs a valid, not empty, scriptblock
throw ($PodeLocale.routeParameterNeedsValidScriptblockExceptionMessage)
if ($PSCmdlet.ParameterSetName -ieq 'File') {
$Routes = Convert-PodeFileToScriptBlock -FilePath $FilePath
}
else {
# The Route parameter needs a valid, not empty, scriptblock
throw ($PodeLocale.routeParameterNeedsValidScriptblockExceptionMessage)
}
}

if ($Path -eq '/') {
Expand Down Expand Up @@ -1580,17 +1609,23 @@ The EndpointName of an Endpoint(s) to use for the Signal Routes.
.PARAMETER IfExists
Specifies what action to take when a Signal Route already exists. (Default: Default)

.PARAMETER FilePath
A literal, or relative, path to a file containing a ScriptBlock for the Route's main logic.

.EXAMPLE
Add-PodeSignalRouteGroup -Path '/signals' -Routes { Add-PodeSignalRoute -Path '/signal1' -Etc }

.EXAMPLE
Add-PodeSignalRouteGroup -Path '/api' -FilePath '/routes/file.ps1'
#>
function Add-PodeSignalRouteGroup {
[CmdletBinding()]
[CmdletBinding(DefaultParameterSetName = 'Routes')]
param(
[Parameter()]
[string]
$Path,

[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true, ParameterSetName = 'Routes' )]
[scriptblock]
$Routes,

Expand All @@ -1601,12 +1636,21 @@ function Add-PodeSignalRouteGroup {
[Parameter()]
[ValidateSet('Default', 'Error', 'Overwrite', 'Skip')]
[string]
$IfExists = 'Default'
$IfExists = 'Default',

[Parameter(Mandatory = $true, ParameterSetName = 'File')]
[string]
$FilePath
)

if (Test-PodeIsEmpty $Routes) {
# The Route parameter needs a valid, not empty, scriptblock
throw ($PodeLocale.routeParameterNeedsValidScriptblockExceptionMessage)
if ($PSCmdlet.ParameterSetName -ieq 'File') {
$Routes = Convert-PodeFileToScriptBlock -FilePath $FilePath
}
else {
# The Route parameter needs a valid, not empty, scriptblock
throw ($PodeLocale.routeParameterNeedsValidScriptblockExceptionMessage)
}
}

if ($Path -eq '/') {
Expand Down Expand Up @@ -2776,4 +2820,4 @@ function Test-PodeSignalRoute {

# check for routes
return (Test-PodeRouteInternal -Method $Method -Path $Path -Protocol $endpoint.Protocol -Address $endpoint.Address)
}
}