$listener = New-Object System.Net.HttpListener
$listener.Prefixes.Add('http://localhost:8081/')
$listener.Start()
Write-Host 'Server running at http://localhost:8081/'

while ($listener.IsListening) {
    $context = $listener.GetContext()
    $request = $context.Request
    $response = $context.Response
    
    $localPath = $request.Url.LocalPath.TrimStart('/')
    if ($localPath -eq '') {
        $localPath = 'hello_world.html'
    }
    
    $fullPath = Join-Path -Path 'd:/GoProject/gitlab/gitee/vlink/Vlink/public/html' -ChildPath $localPath
    
    try {
        $content = Get-Content -Path $fullPath -Raw
        $buffer = [System.Text.Encoding]::UTF8.GetBytes($content)
        $response.ContentLength64 = $buffer.Length
        $response.OutputStream.Write($buffer, 0, $buffer.Length)
    } catch {
        $response.StatusCode = 404
        $content = 'File not found'
        $buffer = [System.Text.Encoding]::UTF8.GetBytes($content)
        $response.ContentLength64 = $buffer.Length
        $response.OutputStream.Write($buffer, 0, $buffer.Length)
    }
    
    $response.Close()
}