Skip to content

Instantly share code, notes, and snippets.

@StartAutomating
StartAutomating / ThereIsNoRouteTable.ps1
Created March 22, 2025 16:13
Gist a web server without a route table
<#
.SYNOPSIS
A pure PowerShell web server
.DESCRIPTION
A pure PowerShell web server proof of concept.
This creates a simple web server that routes commands directly by their local path
That is `/hello` would run the function `/hello` if it exists.
@StartAutomating
StartAutomating / EventBasedServer.ps1
Last active August 8, 2025 17:43
Gist a small event-based HTTP server in PowerShell
$JobName = "http://localhost:$(Get-Random -Min 4200 -Max 42000)/"
$httpListener = [Net.HttpListener]::new()
$httpListener.Prefixes.Add($JobName)
$httpListener.Start()
Start-ThreadJob -ScriptBlock {
param($MainRunspace, $httpListener, $SourceIdentifier = 'http')
while ($httpListener.IsListening) {
$contextAsync = $httpListener.GetContextAsync()
while (-not ($contextAsync.IsCompleted -or $contextAsync.IsFaulted -or $contextAsync.IsCanceled)) {}