Last active
May 6, 2025 12:37
-
-
Save spenkk/48e2597699185b4cbe26d702870e3e30 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$listener = New-Object System.Net.HttpListener; $listener.Prefixes.Add("http://localhost:8080/"); $listener.Start(); while ($listener.IsListening) { $context = $listener.GetContext(); $req = $context.Request; $res = $context.Response; $path = Join-Path (Get-Location) ($req.Url.LocalPath.TrimStart('/')); if (Test-Path $path -PathType Leaf) { $content = [System.IO.File]::ReadAllBytes($path); $res.ContentLength64 = $content.Length; $res.OutputStream.Write($content, 0, $content.Length) } else { $res.StatusCode = 404; $content = [System.Text.Encoding]::UTF8.GetBytes("File not found"); $res.ContentLength64 = $content.Length; $res.OutputStream.Write($content, 0, $content.Length) }; $res.Close() } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment