Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
1,678 additions
and
458 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
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
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,61 @@ | ||
# External Endpoints | ||
|
||
At most times you'll possibly be accessing your Pode server locally. However, you can access your server externally if you setup the endpoints appropriately using the [`Add-PodeEndpoint`](../../Functions/Core/Add-PodeEndpoint) function. These will work on a your VMs, or in a Container. | ||
|
||
!!! tip | ||
In each case, ensure any Firewalls or Network Security Groups are configured to allow access to the port. | ||
|
||
## All Addresses | ||
|
||
The default and common approach is to set your Pode server to listen on all IP addresses: | ||
|
||
```powershell | ||
Add-PodeEndpoint -Address * -Port 8080 -Protocol Http | ||
``` | ||
|
||
With this set, you can access your endpoint using the server's Public, Private IP address or VM name - plus the port number: | ||
|
||
```powershell | ||
Invoke-RestMethod -Uri 'http://<ip-address|vm-name>:8080' | ||
``` | ||
|
||
## IP Address | ||
|
||
The other way to expose your server externally is to create an endpoint using the server's Private/Public IP address. For example, assuming the the server's IP is `10.10.1.5`: | ||
|
||
```powershell | ||
Add-PodeEndpoint -Address 10.10.1.5 -Port 8080 -Protocol Http | ||
``` | ||
|
||
With this set, you can access your endpoint using the server's Private IP address or VM name only - plus the port number: | ||
|
||
```powershell | ||
Invoke-RestMethod -Uri 'http://10.10.1.5:8080' | ||
``` | ||
|
||
## Hostnames | ||
|
||
The final way to expose your server externally is to allow only specific hostnames bound to the server's Private/Public IP address - something like SNI in IIS. | ||
|
||
To do this, let's say you want to allow only `one.pode.com` and `two.pode.com` on a server with IP `10.10.1.5`. The first thing to do is add the hostnames to the server's hosts file (or dns): | ||
|
||
```plain | ||
10.10.1.5 one.pode.com | ||
10.10.1.5 two.pode.com | ||
``` | ||
|
||
Then, create the endpoints within your server: | ||
|
||
```powershell | ||
Add-PodeEndpoint -Address 'one.pode.com' -Port 8080 -Protocol Http | ||
Add-PodeEndpoint -Address 'two.pode.com' -Port 8080 -Protocol Http | ||
``` | ||
|
||
Next, make sure to add the hostnames into your hosts file, or into DNS. | ||
|
||
With these set, you can access your endpoint using only the `one.pode.com` and `two.pode.com` hostnames - plus the port number: | ||
|
||
```powershell | ||
Invoke-RestMethod -Uri 'http://one.pode.com:8080' | ||
Invoke-RestMethod -Uri 'http://two.pode.com:8080' | ||
``` |
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,50 @@ | ||
# Body Parsing | ||
|
||
Pode has inbuilt body/payload parsing on Requests, which by default can parse the following content types: | ||
|
||
* `*/json` | ||
* `*/xml` | ||
* `*/csv` | ||
* `*/x-www-form-urlencoded` | ||
* `multipart/form-data` | ||
|
||
This is useful however, there can be times when you might want to use a different JSON parsing library - or parse a completely different content type altogether! This is possible using the [`Add-PodeBodyParser`](../../../../Functions/Middleware/Add-PodeBodyParser) function. | ||
|
||
## Adding a Parser | ||
|
||
You can use the [`Add-PodeBodyParser`](../../../../Functions/Middleware/Add-PodeBodyParser) function to define a scriptblock that can parse the Request body for a specific content type. Any set parsers have a higher priority than the inbuilt ones, meaning if you define a parser for `application/json` then this will be used instead of the inbuilt one. | ||
|
||
The scriptblock you supply will be supplied a single argument, which will be the Body of the Request. | ||
|
||
For example, to set your own JSON parser that will simply return the body unmodified you could do the following: | ||
|
||
```powershell | ||
Add-PodeBodyParser -ContentType 'application/json' -ScriptBlock { | ||
param($body) | ||
return $body | ||
} | ||
``` | ||
|
||
This can then be accessed the normal way within a Route from the `.Data` object on the supplied event: | ||
|
||
```powershell | ||
Add-PodeRoute -Method Post -Path '/' -ScriptBlock { | ||
param($e) | ||
# if using the above parser, .Data here will just be a plain string | ||
Write-PodeTextResponse -Value $e.Data | ||
} | ||
``` | ||
|
||
This is great if you want to be able to parse other content types like YAML, HCL, or many others! | ||
|
||
## Removing a Parser | ||
|
||
To remove a defined parser you can use the [`Remove-PodeBodyParser`](../../../../Functions/Middleware/Remove-PodeBodyParser) function: | ||
|
||
```powershell | ||
Remove-PodeBodyParser -ContentType 'application/json' | ||
``` | ||
|
||
!!! note | ||
This will only remove defined custom parsers, and will not affect the inbuilt parsers. |
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
Oops, something went wrong.