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

Add switch for AccessControl to create global Options route #981

Merged
merged 1 commit into from
Jun 12, 2022
Merged
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
15 changes: 14 additions & 1 deletion src/Public/Security.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,9 @@ Specifies a value for Access-Control-Max-Age in seconds. (Default: 7200)
.PARAMETER Credentials
Specifies a value for Access-Control-Allow-Credentials

.PARAMETER WithOptions
If supplied, a global Options Route will be created.

.EXAMPLE
Set-PodeSecurityAccessControl -Origin '*' -Methods '*' -Headers '*' -Duration 7200
#>
Expand All @@ -1357,7 +1360,10 @@ function Set-PodeSecurityAccessControl
$Duration = 7200,

[switch]
$Credentials
$Credentials,

[switch]
$WithOptions
)

# origin
Expand Down Expand Up @@ -1394,6 +1400,13 @@ function Set-PodeSecurityAccessControl
if ($Credentials) {
Add-PodeSecurityHeader -Name 'Access-Control-Allow-Credentials' -Value 'true'
}

# opts route
if ($WithOptions) {
Add-PodeRoute -Method Options -Path * -ScriptBlock {
Set-PodeResponseStatus -Code 200
}
}
}

<#
Expand Down