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 9 commits into
base: develop
Choose a base branch
from
45 changes: 40 additions & 5 deletions src/Public/Routes.ps1
eltyBelgium marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -1095,8 +1095,14 @@ 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()]
Expand Down Expand Up @@ -1164,11 +1170,23 @@ function Add-PodeRouteGroup {
$AllowAnon,

[string[]]
$OADefinitionTag
$OADefinitionTag,

[Parameter(Mandatory = $true, ParameterSetName = 'file')]
eltyBelgium marked this conversation as resolved.
Show resolved Hide resolved
[string]
$FilePath
)



if (Test-PodeIsEmpty $Routes) {
throw 'No scriptblock for -Routes passed'
if ($PSCmdlet.ParameterSetName -ieq 'file') {
$Routes = Convert-PodeFileToScriptBlock -FilePath $FilePath
}
else {

throw 'No scriptblock for -Routes passed'
}
}

if ($Path -eq '/') {
Expand Down Expand Up @@ -1567,8 +1585,14 @@ 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()]
Expand All @@ -1588,11 +1612,22 @@ function Add-PodeSignalRouteGroup {
[Parameter()]
[ValidateSet('Default', 'Error', 'Overwrite', 'Skip')]
[string]
$IfExists = 'Default'
$IfExists = 'Default',

[Parameter(Mandatory = $true, ParameterSetName = 'file')]
eltyBelgium marked this conversation as resolved.
Show resolved Hide resolved
[string]
$FilePath
)

i
eltyBelgium marked this conversation as resolved.
Show resolved Hide resolved
if (Test-PodeIsEmpty $Routes) {
throw 'No scriptblock for -Routes passed'
if ($PSCmdlet.ParameterSetName -ieq 'file') {
$Routes = Convert-PodeFileToScriptBlock -FilePath $FilePath
}
else {

throw 'No scriptblock for -Routes passed'
}
}

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

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