Pode
ReleasesGitHub
  • Introduction
  • Getting Started
    • Installation
    • CLI
    • Docker
    • Frontend
  • Tutorials
    • Routes
  • Functions
    • Attach
    • Engine
    • Listen
    • Server
    • Status
    • View
Powered by GitBook
On this page
  • Description
  • Examples
  • Parameters
  1. Functions

Server

Description

The Server function is the most important function throughout all of Pode, as it's the only function that is mandatory in your scripts. Within scriptblock supplied to the Server is where your place all of your main server logic - routes, timers, middleware, etc.

You can only have one Server declared within your script

Examples

  1. The following example will run the scriptblock once, printing out Hello, world!, and then exit:

     Server {
         Write-Host 'Hello, world!'
     }
  2. The following will start a server that repeats the scriptblock every 5 seconds:

     Server -Interval 5 {
         Write-Host 'Hey!'
     }
  3. The following server will accept web requests, and handle them across 2 threads rather than 1:

     Server -Thread 2 {
         # route logic
     }
  4. The following server will restart when it detects a file has been changed. Ie, if you start the server and then alter a web page, or change a dot-sourced script, then the server will restart:

     Server -FileMonitor {
         # route logic
     }

Parameters

Name

Type

Required

Description

Default

ScriptBlock

scriptblock

true

The main closure that contains the core server logic

null

Interval

int

false

Specifies, in seconds, the time to sleep before looping the ScriptBlock logic

0

Threads

int

false

Specifies the number of runspaces used to handle incoming requests

1

DisableTermination

switch

false

Toggles the ability to allow using Ctrl+C to terminate the server

false

DisableLogging

switch

false

Toggles any logging that has been setup. When true all logging is disabled

false

FileMonitor

switch

false

When passed, any file changes will cause the server to restart

false

PreviousListenNextStatus

Last updated 6 years ago