Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #nosp.nim / main
- import nosppkg/async_server
- import asyncdispatch
- when isMainModule:
- asyncCheck serve() #from here
- runForever()
- #async_server
- import asynchttpserver, asyncdispatch, strutils
- import templates/home as th
- import templates/static as ts
- proc parseRequest(req: Request) {.async.} =
- if "css/" in req.url.path:
- await ts.serveStatic(req) #to here
- else:
- await req.respond(Http200, th.index())
- proc serve*() {.async.} =
- var server = newAsyncHttpServer()
- proc cb(req: Request) {.async.} =
- await parseRequest(req)
- waitFor server.serve(Port(5000), cb)
- #static.min
- import asynchttpserver, asyncdispatch, strutils, os, tables
- var fileTable = initTable[string, string]()
- proc getFileCont(path: string): string =
- let f = fileTable.hasKey(path) #to here
- "sdflkj"
- proc serveStatic*(req: Request) {.async.} =
- await req.respond(Http200, getFileCont(req.url.path))
- # error
- ... C:\Users\sveri\IdeaProjects\nim\nosp\src\nosppkg\async_server.nim(12, 17) template/generic instantiation of `async` from here
- ... C:\Users\sveri\IdeaProjects\nim\nosp\src\nosppkg\async_server.nim(18, 17) Error: type mismatch: got <AsyncHttpServer, Port, proc (req: Request): Future[system.void]{.locks: <unknown>.}>
- ... but expected one of:
- ... proc serve(server: AsyncHttpServer; port: Port;
- ... callback: proc (request: Request): Future[void] {.closure, gcsafe.};
- ... address = ""): owned(Future[void])
- ... first type mismatch at position: 3
- ... required type for callback: proc (request: Request): Future[system.void]{.closure, gcsafe.}
- ... but expression 'cb' is of type: proc (req: Request): Future[system.void]{.locks: <unknown>.}
- ... This expression is not GC-safe. Annotate the proc with {.gcsafe.} to get extended error information.
- ... 1 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them
- ... expression: serve(server, Port(5000), cb)
Advertisement
Add Comment
Please, Sign In to add comment