Created
August 6, 2024 15:30
-
-
Save btbytes/9a9f45047ce8ec38c9d31dba126f7b26 to your computer and use it in GitHub Desktop.
Revisions
-
btbytes created this gist
Aug 6, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ import std/[asynchttpserver, asyncdispatch, os, strutils] proc handleRequest(req: Request) {.async.} = let path = "." & req.url.path if fileExists(path): let content = readFile(path) let contentType = case path.splitFile.ext of ".html": "text/html" of ".css": "text/css" of ".js": "application/javascript" else: "application/octet-stream" await req.respond(Http200, content, newHttpHeaders({"Content-Type": contentType})) else: await req.respond(Http404, "404 Not Found") proc main() = let server = newAsyncHttpServer() waitFor server.serve(Port(8080), handleRequest) main()