Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Start-PodeServer -ScriptBlock {
Add-PodeEndPoint -Address localhost -port 32005 -Protocol Http

Add-PodeRoute -Method Get -Path '/ping' -ScriptBlock {
Write-PodeJsonResponse -Value @{value = 'pong' }
Write-PodeJsonResponse -Value @{ value = 'pong' }
}
}

Expand Down
6 changes: 3 additions & 3 deletions docs/Getting-Started/Console.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The behavior, appearance, and functionality of the console are highly customizab
### Configurable Settings via `Start-PodeServer`

| **Parameter** | **Description** |
|-----------------------|--------------------------------------------------------------------------------------------------|
| --------------------- | ------------------------------------------------------------------------------------------------ |
| `DisableTermination` | Prevents termination, suspension, or resumption of the server via keyboard interactive commands. |
| `DisableConsoleInput` | Disables all console keyboard interactions for the server. |
| `ClearHost` | Clears the console whenever the server changes state (e.g., running → suspend → resume). |
Expand Down Expand Up @@ -201,12 +201,12 @@ Redefine the key for terminating the server:

## Customizing Console Colors

The console colors are fully customizable via the `Colors` section of the configuration. Each element of the console can have its color defined using PowerShell color names. Heres what each color setting controls:
The console colors are fully customizable via the `Colors` section of the configuration. Each element of the console can have its color defined using PowerShell color names. Here's what each color setting controls:

### Color Settings

| **Key** | **Default Value** | **Description** |
|---------------------|-------------------|------------------------------------------------------------------------|
| ------------------- | ----------------- | ---------------------------------------------------------------------- |
| `Header` | `White` | The server's header section, including the Pode version and timestamp. |
| `EndpointsHeader` | `Yellow` | The header for the endpoints list. |
| `Endpoints` | `Cyan` | The endpoints themselves, including protocol and URLs. |
Expand Down
6 changes: 3 additions & 3 deletions docs/Getting-Started/Debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ These default names are automatically assigned by Pode, making it easier to iden

### Customizing Runspace Names

By default, Podes Tasks, Schedules, and Timers label their associated runspaces with their own names (as shown above). This simplifies the identification of runspaces when debugging or reviewing logs.
By default, Pode's Tasks, Schedules, and Timers label their associated runspaces with their own names (as shown above). This simplifies the identification of runspaces when debugging or reviewing logs.

However, if a different runspace name is needed, Pode allows you to customize it. Inside the script block of `Add-PodeTask`, `Add-PodeSchedule`, or `Add-PodeTimer`, you can use the `Set-PodeCurrentRunspaceName` cmdlet to assign any custom name you prefer.

Expand All @@ -211,7 +211,7 @@ This cmdlet sets a custom name for the runspace, making it easier to track durin

#### Example

Heres an example that demonstrates how to set a custom runspace name in a Pode task:
Here's an example that demonstrates how to set a custom runspace name in a Pode task:

```powershell
Add-PodeTask -Name 'Test2' -ScriptBlock {
Expand All @@ -237,7 +237,7 @@ This cmdlet returns the name of the current runspace, allowing for easier tracki

#### Example

Heres an example that uses `Get-PodeCurrentRunspaceName` to output the runspace name during the execution of a schedule:
Here's an example that uses `Get-PodeCurrentRunspaceName` to output the runspace name during the execution of a schedule:

```powershell
Add-PodeSchedule -Name 'TestSchedule' -Cron '@hourly' -ScriptBlock {
Expand Down
180 changes: 90 additions & 90 deletions docs/Getting-Started/Migrating/0X-to-1X.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Getting-Started/pwshsupportpolicy.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Pode is tested against the PowerShell versions it supports at the time of each r
A warning mechanism within Pode detects the PowerShell version in use at runtime. If a version no longer supported by the current release of Pode is detected—due to reaching EOL—a warning will be issued, advising on the potential risks and recommending an update to a supported version.

## Version Updates and Communication
Updates to the PowerShell version support policy will be documented in Podes release notes and official documentation. Users are encouraged to review these sources to stay informed about which PowerShell versions are supported by their version of Pode.
Updates to the PowerShell version support policy will be documented in Pode's release notes and official documentation. Users are encouraged to review these sources to stay informed about which PowerShell versions are supported by their version of Pode.

## Feedback and Contributions
Feedback on Pode's PowerShell version support policy is invaluable. We welcome suggestions and contributions from our community to help refine and improve our approach. Please share your thoughts through our GitHub repository or community forums.
Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorials/Authentication/Inbuilt/AzureAD.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ When a user accesses your site unauthenticated, they will be to Azure to login,

### Password

To setup Azure AD authentcation, but using your own Form login, then you can use the `-InnerScheme` parameter on `New-PodeAuthAzureADScheme`:
To setup Azure AD authentication, but using your own Form login, then you can use the `-InnerScheme` parameter on `New-PodeAuthAzureADScheme`:

```powershell
Start-PodeServer {
Expand Down
42 changes: 27 additions & 15 deletions docs/Tutorials/Basics.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Basics
<sub><b>!!! Warning</b>
You can initiate only one server per PowerShell instance. To run multiple servers, start additional PowerShell, or pwsh, sessions. Each session can run its own server. This is fundamental to how Pode operates, so consider it when designing your scripts and infrastructure.</sub>

!!! important
You can only initiate one Pode server per PowerShell instance.

While it’s not mandatory, we strongly recommend importing the Pode module with a specified maximum version. This practice helps to prevent potential issues arising from breaking changes introduced in new major versions:
## Importing

While it's not mandatory, we strongly recommend importing the Pode module with a specified maximum version. This practice helps to prevent potential issues arising from breaking changes introduced in new major versions:

```powershell
Import-Module -Name Pode -MaximumVersion 2.99.99
```

To further enhance the robustness of your code, consider wrapping the import statement within a try/catch block. This way, if the module fails to load, your script wont proceed, preventing possible errors or unexpected behavior:
To further enhance the robustness of your code, consider wrapping the import statement within a try/catch block. This way, if the module fails to load, your script won't proceed, preventing possible errors or unexpected behaviour:

```powershell
try {
Expand All @@ -20,34 +22,40 @@ try {
}
```

The script for your server should be set in the [`Start-PodeServer`](../../Functions/Core/Start-PodeServer) function, via the `-ScriptBlock` parameter. The following example will listen over HTTP on port 8080, and expose a simple HTML page of running processes at `http://localhost:8080/processes`:
## Running

To start a new Pode server use [`Start-PodeServer`](../../Functions/Core/Start-PodeServer), and supply your server's logic via the `-ScriptBlock` parameter.

The following example will listen over HTTP on port 8080, and expose a simple Route that returns the host's name at `http://localhost:8080/`:

```powershell
Start-PodeServer {
# attach to port 8080 for http
Add-PodeEndpoint -Address * -Port 8080 -Protocol Http
Add-PodeEndpoint -Address localhost -Port 8080 -Protocol Http

# a simple page for displaying services
Add-PodePage -Name 'processes' -ScriptBlock { Get-Process }
# a simple route that returns the host's name
Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
@{ Name = $env:COMPUTERNAME } | Write-PodeJsonResponse
}
}
```

To start the server you can either:

* Directly run the `./server.ps1` script, or
* If you've created a `package.json` file, ensure the `./server.ps1` script is set as your `main` or `scripts/start`, then just run `pode start` (more [here](../../Getting-Started/CLI))
* If you created a `package.json` file, ensure the `./server.ps1` script is set as your `main` or `scripts/start`, then just run `pode start` (more [here](../../Getting-Started/CLI))

## Terminating

Once your Pode server has started, you can terminate it at any time using `Ctrl+C`. If you want to disable your server from being terminated then use the `-DisableTermination` switch on the [`Start-PodeServer`](../../Functions/Core/Start-PodeServer) function.
Once your Pode server has started, you can terminate it at any time using `Ctrl+C`. If you want to disable your server from being terminated then use the `-DisableTermination` switch on [`Start-PodeServer`](../../Functions/Core/Start-PodeServer).

## Restarting

You can restart your Pode server by using `Ctrl+R`, or on Unix you can also use `Shift+C` and `Shift+R` as well. When the server restarts it will only re-invoke the initial `-ScriptBlock`, so any changes made to this main scriptblock will *not* be reflected - you'll need to terminate and start your server again.

## Script from File

You can also define your server's scriptblock in a separate file, and use it via the `-FilePath` parameter on the [`Start-PodeServer`](../../Functions/Core/Start-PodeServer) function.
You can define your server's scriptblock in a separate file, and load it via the `-FilePath` parameter on [`Start-PodeServer`](../../Functions/Core/Start-PodeServer).

Using this approach there are 2 ways to start you server:

Expand Down Expand Up @@ -83,13 +91,17 @@ PS> Start-PodeServer -FilePath './File.ps1'
!!! tip
Normally when you restart your Pode server any changes to the main scriptblock don't reflect. However, if you reference a file instead, then restarting the server will reload the scriptblock from that file - so any changes will reflect.

## Internationalization
## App Name

Primarily used by logging, the default application name of your server will be "Pode". You can customise this name via the `-AppName` parameter on [`Start-PodeServer`](../../Functions/Core/Start-PodeServer).

## Localisation

Pode has built-in support for internationalization (i18n). By default, Pode uses the `$PsUICulture` variable to determine the User Interface Culture (UICulture).
Pode has built-in support for localisation. By default, Pode uses the `$PsUICulture` variable to determine the User Interface Culture (UICulture).

You can enforce a specific localization when importing the Pode module by using the UICulture argument. This argument accepts a culture code, which specifies the language and regional settings to use.
You can enforce a specific localisation when importing the Pode module by using the UICulture argument. This argument accepts a culture code, which specifies the language and regional settings to use.

Heres an example of how to enforce Korean localization:
Here's an example of how to enforce Korean localisation:

```powershell
Import-Module -Name Pode -ArgumentList 'ko-KR'
Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorials/CORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Pode simplifies handling CORS by providing the `Set-PodeSecurityAccessControl` f

### Setting CORS Headers instead

The `Set-PodeSecurityAccessControl` function allows you to set these headers easily. Heres how you can address common CORS challenges using this function:
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
Expand Down
173 changes: 173 additions & 0 deletions docs/Tutorials/Logging/Formatting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# Formatting

You can customise the formatting and serialisation of your Log Types, by supplying the parameters as described below.

Within the scope of a Log Type, ie the "Transform Phase", the steps are as follows:

```mermaid
graph LR
Selection("`Selection`")

Serialisation("`Serialisation`")

Formatting("`Formatting`")

Selection --> Serialisation
Serialisation --> Formatting
```

| Step | Description | Related Parameters |
| ------------- | --------------------------------------------------------------------------------------- | ---------------------------------------------- |
| Selection | Required data from the original log item is selected, and returned (ie, as a hashtable) | `-ScriptBlock` |
| Serialisation | The resultant data, if required, is serialised (ie, as JSON, custom, etc.) | `-SerialiseFormat` and `-SerialiseScriptBlock` |
| Formatting | The resultant, or serialised, data is converted into some log format (ie, syslog) | `-LogFormat` and `-LogScriptBlock` |

## Serialisation

Log Types support the following serialisation methods, which can be supplied using the `-SerialiseFormat` parameter:

* None
* Custom
* Json
* Xml
* Yaml

The default for inbuilt Log Types like Error/Request is None, while the default for custom Log Types is None.

### None

When None is specified, no serialisation method is applied and the data returned by the Log Type's `-ScriptBlock` is passed straight to formatting.

### Custom

When Custom is specified then a `-SerialiseScriptBlock` is required to be supplied as well.

!!! note
For inbuilt Log Types, like Error/Request, "Custom" is the default. Here a `-SerialiseScriptBlock` is optional as inbuilt logic will be used if not supplied.

When serialisation occurs, this scriptblock will be invoked. Supplied to this scriptblock are the following parameters:

1. The resultant data returned from the Log Type's main `-ScriptBlock`
2. The [Log Event](../Objects#log-event) object
3. Items supplied to `-ArgumentList`, splatted as individual parameters

For example, the inbuilt Request Log Type's serialise scriptblock looks as follows; it will serialise the data into Combined Log Format:

```powershell
$scriptblock = {
param($data)
$reqLine = "$($data.Method) $($data.Resource) $($data.Protocol)"
return "$($data.Host) $($data.Identifier) $($data.User) [$($data.Date)] `"$($reqLine)`" $($data.StatusCode) $($data.Size) `"$($data.Referrer)`" `"$($data.UserAgent)`""
}
```

ie:
```plain
10.10.0.3 - - [14/Jun/2018:20:23:52 +01:00] "GET /api/users HTTP/1.1" 200 9001 "-" "<user-agent>"
```

### Others

The other standard serialisation options: JSON; XML; and YAML, will all serialise the resultant data returned from the Log Type's main `-ScriptBlock`.

For example, if you supply `-SerialiseFormat Json` to [`Enable-PodeLogRequestType`](../../../../Functions/Logging/Enable-PodeLogRequestType), then instead of Combined Log Format (the default) you'll get:

```powershell
New-PodeLogTerminalMethod | Enable-PodeLogRequestType -SerialiseFormat Json
```

```json
{
"Host": "10.10.0.3",
"Identifier": null,
"User": null,
"Date": "14/Jun/2018:20:23:52 +01:00",
"Method": "GET",
"Resource": "/api/users",
"Protocol": "HTTP/1.1",
"StatusCode": 200,
"Size": 9001,
"Referrer": "",
"UserAgent": "<user-agent>"
}
```

#### XML

When serialising custom Log Types into XML the default root element is `<root>`, this can be customised via `-XmlRootName`.

### Global

You can configure a global serialisation format to use via [`Set-PodeLogDefaultSerialiseFormat`]. If you **don't** supply `-SerialiseFormat` then the global default will be used instead.

By default there is no global default; not supplying `-SerialiseFormat` will default to the Log Type's local default value - format inbuilt type this is Custom, and for custom types this is None.

## Log Format

Log Types support the following formats, which can be supplied using the `-LogFormat` parameter:

* None (default)
* Custom
* Syslog

This occurs after serialisation, so the "message" will typically be the resultant data from the Log Type, and post any serialisation. For example, allowing you to have a syslog formatted message, where the message part is JSON.

### None

When None is specified, then no formatting is performed on the log item. Whatever resultant data was returned from the Log Type's `-ScriptBlock`, and optionally supplied to any serialisation, will remain as is.

### Custom

When Custom is specified then a `-LogScriptBlock` is required to be supplied as well.

When log formatting occurs, after serialisation, this scriptblock will be invoked. Supplied to this scriptblock are the following parameters:

1. The resultant data returned from the Log Type's main `-ScriptBlock`, and after any serialisation
2. The [Log Event](../Objects#log-event) object
3. Items supplied to `-ArgumentList`, splatted as individual parameters

For example, a simple pipe-delimited format of `<LEVEL>|<DATETIME>|<MESSAGE>:

```powershell
$scriptblock = {
param($data, $logEvent)
return "$($logEvent.Level)|$($logEvent.Timestamp)|$($data)
}
```

### Syslog

When Syslog is specified, then the resultant data - after serialisation - is set as the "message" component of a syslog formatted string ([more details](https://www.manageengine.com/products/eventlog/logging-guide/syslog/syslog-basics-logging.html)). Supported are the following formats:

* RFC5424 (default)
* RFC3164

By default, this will be RFC5424 format with a facility value of 16 (local0). These values can be customised, and tags included, by creating a `SyslogInfo` object via [`New-PodeLogSyslogInfo`](../../../../Functions/Logging/New-PodeLogSyslogInfo); the result of which can then be supplied to a Log Type's `-SyslogInfo` parameter.

For example if you specify `-LogFormat Syslog` on [`Enable-PodeLogRequestType`](../../../../Functions/Logging/Enable-PodeLogRequestType), with no `-SyslogInfo` object, then the result syslog message sent to a Log Method would be RFC5424 format:

```powershell
New-PodeLogTerminalMethod | Enable-PodeLogRequestType -LogFormat Syslog
```

```plain
<134>1 2018-06-14T20:23:52.000+01:00 APP-VM-1 Pode 6132 - - 10.10.0.3 - - [14/Jun/2018:20:23:52 +01:00] "GET /api/users HTTP/1.1" 200 9001 "-" "<user-agent>"
```

!!! note
The application name used, if not specified in a SyslogInfo object, will be the [Server's App Name](../../../../Basic#app-name).

To change the format to RFC3164:

```powershell
$syslogInfo = New-PodeLogSyslogInfo -Format RFC3164
New-PodeLogTerminalMethod | Enable-PodeLogRequestType -LogFormat Syslog -SyslogInfo $syslogInfo
```

### Global

You can configure a global log format to use via [`Set-PodeLogDefaultFormat`]. If you **don't** supply `-LogFormat` then the global default will be used instead.

By default there is no global default; not supplying `-LogFormat` will default to the Log Type's local default value - usually None.

The same can also be done for syslog formatting using [`Set-PodeLogDefaultSyslogFormat`]. Similar to above this will apply when either no `-SyslogInfo` is supplied, or no `-Format` is supplied to [`New-PodeLogSyslogInfo`].
Loading
Loading