Skip to content

Instantly share code, notes, and snippets.

@mrwonko
Last active November 8, 2018 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrwonko/9e59750c13ad411c9945b918bb8c5a11 to your computer and use it in GitHub Desktop.
Save mrwonko/9e59750c13ad411c9945b918bb8c5a11 to your computer and use it in GitHub Desktop.
import asynchttpserver, asyncdispatch
from strformat import `&`
proc main() =
let local = "123"
proc serveIndex(req: Request) {.async, gcsafe.} =
await req.respond(Http200, &"{local}")
proc serve404(req: Request) {.async, gcsafe.} =
echo req.url.path
await req.respond(Http404, "not found")
proc serve(req: Request) {.async, gcsafe.} =
let handler = case req.url.path:
of "/":
serveIndex
else:
serve404
await handler(req)
let server = newAsyncHttpServer()
waitFor server.serve(Port(8080), serve, address = "127.0.0.1")
when isMainModule:
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment