31 lines
1.1 KiB
PowerShell
31 lines
1.1 KiB
PowerShell
$port = 3456
|
|
$root = $PSScriptRoot
|
|
$listener = [System.Net.HttpListener]::new()
|
|
$listener.Prefixes.Add("http://localhost:$port/")
|
|
$listener.Start()
|
|
Write-Host "Serving on http://localhost:$port/"
|
|
while ($listener.IsListening) {
|
|
$ctx = $listener.GetContext()
|
|
$path = $ctx.Request.Url.LocalPath.TrimStart('/')
|
|
if ($path -eq '') { $path = 'JGA_Info.html' }
|
|
$file = Join-Path $root $path
|
|
if (Test-Path $file) {
|
|
$ext = [System.IO.Path]::GetExtension($file).ToLower()
|
|
$mime = switch ($ext) {
|
|
'.html' { 'text/html; charset=utf-8' }
|
|
'.jpg' { 'image/jpeg' }
|
|
'.jpeg' { 'image/jpeg' }
|
|
'.png' { 'image/png' }
|
|
default { 'application/octet-stream' }
|
|
}
|
|
$bytes = [System.IO.File]::ReadAllBytes($file)
|
|
$ctx.Response.ContentType = $mime
|
|
$ctx.Response.SendChunked = $true
|
|
$ctx.Response.OutputStream.Write($bytes, 0, $bytes.Length)
|
|
$ctx.Response.OutputStream.Flush()
|
|
} else {
|
|
$ctx.Response.StatusCode = 404
|
|
}
|
|
$ctx.Response.Close()
|
|
}
|