Created
May 1, 2014 22:10
-
-
Save dom96/49427cd0a9c8da47fff3 to your computer and use it in GitHub Desktop.
This file contains 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
import asynchttpserver, httpclient, parseurl, asyncdispatch, strtabs, strutils | |
var server = newAsyncHttpServer() | |
proc onRequest(req: TRequest) {.async.} = | |
var client = newAsyncHttpClient() | |
var htmlResp = "" | |
try: | |
let reqResp = await client.get(req.url.path) | |
htmlResp = | |
if reqResp.status.startsWith("200"): "It's up!" | |
else: "It's down :(" | |
except EOS: | |
htmlResp = "It's down :(" | |
let headers = {"Content-Type": "text/html"} | |
echo("Replying with: ", htmlResp) | |
await req.respond(Http200, htmlResp, headers.newStringTable) | |
server.serve(TPort(8080), onRequest) | |
runForever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment