Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
<# This creates a web server on port 8080 It servers up output from this script. example: http://localhost:8080/hello This does not server files or directories #> $routes = @{ "/hello" = { return 'Hello world!' } } $url = 'http://localhost:8080/' $listener = New-Object System.Net.HttpListener $listener.Prefixes.Add($url) $listener.Start() Write-Host "Listening at $url..." while ($listener.IsListening) { $context = $listener.GetContext() $requestUrl = $context.Request.Url $response = $context.Response Write-Host '' Write-Host "> $requestUrl" $localPath = $requestUrl.LocalPath $route = $routes.Get_Item($requestUrl.LocalPath) if ($route -eq $null) { $response.StatusCode = 404 } else { $content = & $route $buffer = [System.Text.Encoding]::UTF8.GetBytes($content) $response.ContentLength64 = $buffer.Length $response.OutputStream.Write($buffer, 0, $buffer.Length) } $response.Close() $responseStatus = $response.StatusCode Write-Host "< $responseStatus" }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)