Skip to content

Instantly share code, notes, and snippets.

@grenade
Created November 11, 2016 11:28
Show Gist options
  • Save grenade/cac6541a1ab82039a31d8008d1fb08c5 to your computer and use it in GitHub Desktop.
Save grenade/cac6541a1ab82039a31d8008d1fb08c5 to your computer and use it in GitHub Desktop.
$www = 'c:\log'
$listener = New-Object Net.HttpListener
$listener.Prefixes.Add("http://+:8000/")
$listener.Start()
While ($listener.IsListening) {
$context = $listener.GetContext()
$response = $context.Response
if ($context.Request.RawUrl.length -gt 1) {
$response.Headers.Add("Content-Type","text/plain")
$content = Get-Content (Join-Path $www $context.Request.RawUrl)
} else {
$response.Headers.Add("Content-Type","application/json")
$content = ConvertTo-Json @(Get-ChildItem -Path $www | ? { !$_.PSIsContainer -and $_.Name.EndsWith('.log') -and $_.Length -gt 0 } | % { $_.Name })
}
$bytes = [Text.Encoding]::UTF8.GetBytes($content)
$response.ContentLength64 = $bytes.Length
$response.OutputStream.Write($bytes, 0, $bytes.Length)
$response.Close()
}
$listener.Stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment