forked from Badgerati/Pode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into Issue-Badgerati#1329
- Loading branch information
Showing
126 changed files
with
6,539 additions
and
2,013 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "Codespace with PowerShell, Pester, Invoke-Build, and .NET 8", | ||
"image": "mcr.microsoft.com/vscode/devcontainers/base:ubuntu", | ||
"features": { | ||
"ghcr.io/devcontainers/features/powershell:1": {}, | ||
"ghcr.io/devcontainers/features/dotnet:1": { | ||
"version": "8.0" | ||
} | ||
}, | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"ms-vscode.powershell", | ||
"pspester.pester-test" | ||
] | ||
} | ||
}, | ||
"postCreateCommand": "pwsh -Command 'Install-Module -Name InvokeBuild,Pester -Force -SkipPublisherCheck; sleep 5; Invoke-Build Build '" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ jobs: | |
name: Add issue to project | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected].1 | ||
- uses: actions/[email protected].2 | ||
with: | ||
project-url: https://github.com/users/Badgerati/projects/2 | ||
github-token: ${{ secrets.PROJECT_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ jobs: | |
name: Add issue to project | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected].1 | ||
- uses: actions/[email protected].2 | ||
with: | ||
project-url: https://github.com/users/Badgerati/projects/2 | ||
github-token: ${{ secrets.PROJECT_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
# GitHub Codespace and Pode | ||
|
||
GitHub Codespaces provides a cloud-based development environment directly integrated with GitHub. This allows you to set up your development environment with pre-configured settings, tools, and extensions. In this guide, we will walk you through using GitHub Codespace to work with Pode, a web framework for building web applications and APIs in PowerShell. | ||
|
||
## Prerequisites | ||
|
||
- A GitHub account | ||
- A repository set up for your Pode project, including the `devcontainer.json` configuration file. | ||
|
||
## Launching GitHub Codespace | ||
|
||
1. **Open GitHub Codespace:** | ||
|
||
Go to your GitHub repository on the web. Click on the green `Code` button, and then select `Open with Codespaces`. If you don't have any Codespaces created, you can create a new one by clicking `New codespace`. | ||
|
||
2. **Codespace Initialization:** | ||
|
||
Once the Codespace is created, it will use the existing `devcontainer.json` configuration to set up the environment. This includes installing the necessary VS Code extensions and PowerShell modules specified in the configuration. | ||
|
||
3. **Verify the Setup:** | ||
|
||
- The terminal in the Codespace will default to PowerShell (`pwsh`). | ||
- Check that the required PowerShell modules are installed by running: | ||
|
||
```powershell | ||
Get-Module -ListAvailable | ||
``` | ||
You should see `InvokeBuild` and `Pester` listed among the available modules. | ||
## Running a Pode Application | ||
1. **Use an Example Pode Project:** | ||
Pode comes with several examples in the `examples` folder. You can run one of these examples to verify that your setup is working. For instance, let's use the `HelloWorld` example. | ||
2. **Open HelloWorld** | ||
Navigate to the `examples/HelloWorld` directory and open the `HelloWorld.ps1` file | ||
3. **Run the sample** | ||
Run the Pode server by executing the `HelloWorld.ps1` script in the PowerShell terminal: | ||
```powershell | ||
./examples/HelloWorld/HelloWorld.ps1 | ||
``` | ||
or using the `Run/Debug` on the UI | ||
|
||
4. **Access the Pode Application:** | ||
|
||
Once the Pode server is running, you can access your Pode application by navigating to the forwarded port provided by GitHub Codespaces. This is usually indicated by a URL in the terminal or in the Codespaces interface. | ||
|
||
For more information on using Pode and its features, refer to the [Pode documentation](https://badgerati.github.io/Pode/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
|
||
# CORS | ||
|
||
## What is CORS? | ||
Cross-Origin Resource Sharing (CORS) is a security feature implemented by web browsers to restrict web pages from making requests to a different domain than the one that served the web page. This is a critical aspect of web security, helping to prevent malicious sites from accessing sensitive data from another domain. | ||
|
||
## CORS Challenges | ||
When developing web applications, you may encounter situations where your web page needs to request resources from a different domain. This can lead to CORS errors if the appropriate headers are not set to allow these cross-origin requests. Common challenges include: | ||
- Handling pre-flight requests. | ||
- Allowing specific methods and headers. | ||
- Managing credentials in cross-origin requests. | ||
- Setting the appropriate origins. | ||
|
||
## Addressing CORS Challenges | ||
|
||
Pode simplifies handling CORS by providing the `Set-PodeSecurityAccessControl` function, which allows you to define the necessary headers to manage cross-origin requests effectively. | ||
|
||
### Key Headers for CORS | ||
|
||
1. **Access-Control-Allow-Origin**: Specifies which origins are permitted to access the resource. | ||
2. **Access-Control-Allow-Methods**: Lists the HTTP methods that are allowed when accessing the resource. | ||
3. **Access-Control-Allow-Headers**: Indicates which HTTP headers can be used during the actual request. | ||
4. **Access-Control-Max-Age**: Specifies how long the results of a pre-flight request can be cached. | ||
5. **Access-Control-Allow-Credentials**: Indicates whether credentials are allowed in the request. | ||
|
||
### Setting CORS Headers instead | ||
|
||
The `Set-PodeSecurityAccessControl` function allows you to set these headers easily. Here’s how you can address common CORS challenges using this function: | ||
|
||
1. **Allowing All Origins** | ||
```powershell | ||
Set-PodeSecurityAccessControl -Origin '*' | ||
``` | ||
This sets the `Access-Control-Allow-Origin` header to allow requests from any origin. | ||
|
||
2. **Specifying Allowed Methods** | ||
```powershell | ||
Set-PodeSecurityAccessControl -Methods 'GET', 'POST', 'OPTIONS' | ||
``` | ||
This sets the `Access-Control-Allow-Methods` header to allow only the specified methods. | ||
|
||
3. **Specifying Allowed Headers** | ||
```powershell | ||
Set-PodeSecurityAccessControl -Headers 'Content-Type', 'Authorization' | ||
``` | ||
This sets the `Access-Control-Allow-Headers` header to allow the specified headers. | ||
|
||
4. **Handling Credentials** | ||
```powershell | ||
Set-PodeSecurityAccessControl -Credentials | ||
``` | ||
This sets the `Access-Control-Allow-Credentials` header to allow credentials in requests. | ||
|
||
5. **Setting Cache Duration for Pre-flight Requests** | ||
```powershell | ||
Set-PodeSecurityAccessControl -Duration 3600 | ||
``` | ||
This sets the `Access-Control-Max-Age` header to cache the pre-flight request for one hour. | ||
|
||
6. **Automatic Header and Method Detection** | ||
```powershell | ||
Set-PodeSecurityAccessControl -AutoHeaders -AutoMethods | ||
``` | ||
These parameters automatically populate the list of allowed headers and methods based on your OpenApi definition and defined routes, respectively. | ||
|
||
7. **Enabling Global OPTIONS Route** | ||
```powershell | ||
Set-PodeSecurityAccessControl -WithOptions | ||
``` | ||
This creates a global OPTIONS route to handle pre-flight requests automatically. | ||
|
||
8. **Additional Security with Cross-Domain XHR Requests** | ||
```powershell | ||
Set-PodeSecurityAccessControl -CrossDomainXhrRequests | ||
``` | ||
This adds the 'x-requested-with' header to the list of allowed headers, enhancing security. | ||
|
||
### Example Configuration | ||
|
||
Here is an example of configuring CORS settings in Pode using `Set-PodeSecurityAccessControl`: | ||
|
||
```powershell | ||
Set-PodeSecurityAccessControl -Origin 'https://example.com' -Methods 'GET', 'POST' -Headers 'Content-Type', 'Authorization' -Duration 7200 -Credentials -WithOptions -AutoHeaders -AutoMethods -CrossDomainXhrRequests | ||
``` | ||
|
||
This example sets up CORS to allow requests from `https://example.com`, allows `GET` and `POST` methods, permits `Content-Type` and `Authorization` headers, enables credentials, caches pre-flight requests for two hours, automatically detects headers and methods, and allows cross-domain XHR requests. | ||
|
||
### More Information on CORS | ||
|
||
For more information on CORS, you can refer to the following resources: | ||
- [Fetch Living Standard](https://fetch.spec.whatwg.org/) | ||
- [CORS in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-7.0#credentials-in-cross-origin-requests) | ||
- [MDN Web Docs on CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) |
Oops, something went wrong.