Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a -FilePath parameter to the RouteGroup functions #1331

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 60 additions & 16 deletions src/Public/Routes.ps1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the new -FilePath parameter, it'd be worth adding a quick mention of the parameter in the docs found at /docs/Tutorials/Routes/Utilities/RouteGrouping.md. At the bottom of the ## Routes section, a quick nod the the -FilePath parameter and an example will do 😄

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This -FilePath parameter is missing the .PARAMETER definition above the function

)

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)
}
}
Loading