You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
proc hello*(ctx: Context) {.async.} =
var
s: string
s = templates.renderTemplate("main.html", %*{"faa": "super"}) # If removed, the problem will disappear.
resp "Main page from plugin!" & genUid() & ctx.request.hostName() & s
I had the same problem. Proc hello has to be of type HandlerAsync, which is proc(ctx: Context): Future[void] {.closure, gcsafe.}. hello is not GC-safe, because it accesses a global variable templates. At least that's what the compiler should say if you add .gcsafe pragma to the proc.
I have problems with the handler. When I try to call some functions in the body of the handler, I get an error. How to deal with it?
My code:
`import prologue
import fastcmspkg/utils
import prologue/core/uid
import tinypool/sqlitePool
import db_connector/db_sqlite
import tinypool/core
import fastcmspkg/templates/nwt
var templates: Nwt
proc hello*(ctx: Context) {.async.} =
var
s: string
s = templates.renderTemplate("main.html", %*{"faa": "super"}) # If removed, the problem will disappear.
resp "Main page from plugin!" & genUid() & ctx.request.hostName() & s
proc Init(app: Prologue, db_pool: ConnectionPool[DbConn], templ: Nwt){.exportPlugin.} =
SQLITE_POOL = db_pool
templates = templ
echo "init plugin " & instantiationInfo().filename
app.get("/", hello) # this error!`
My console log:
d:\nim-2.0.0\projects\fastcms\src\plugins\main page\main_page.nim(32, 6) Error: type mismatch
Expression: get(app, "/", hello)
[1] app: Prologue
[2] "/": string
[3] hello: proc (ctx: Context): Future[system.void]
Expected one of (first mismatch at [position]):
[1] func get(env: Env; key: string): string
[1] proc get(group: Group; route: string; handler: HandlerAsync; name = "";
middlewares: openArray[HandlerAsync] = @[])
[1] proc get[T](self: Option[T]): lent T
[1] proc get[T](self: Option[T]; otherwise: T): T
[1] proc get[T](self: var Option[T]): var T
[3] proc get(app: Prologue; route: string; handler: HandlerAsync; name = "";
middlewares: openArray[HandlerAsync] = @[])
The text was updated successfully, but these errors were encountered: