dom96 / jester

A sinatra-like web framework for Nim.
MIT License
1.58k stars 120 forks source link

Redirects can no longer be used in error blocks #269

Closed reesmichael1 closed 2 years ago

reesmichael1 commented 4 years ago

First, thanks for all your work on Jester! It's a very nice framework.

It seems that it's no longer possible to use a redirect within an error block with 0.5.0. With Jester 0.4.3, this snippet compiles and works as expected:

import jester

router root:
  get "/":
    resp "hello world"

  error Http404:
    redirect "404.html"

proc main() =
  var jester = initJester(root)
  jester.serve()

when isMainModule:
  main()

With 0.5.0, I get the following compilation error:

/home/reesmichael1/programs/scorecord/example.nim(4, 8) template/generic instantiation of `router` from here
/home/reesmichael1/.nimble/pkgs/jester-0.5.0/jester.nim(1331, 39) template/generic instantiation of `async` from here
/home/reesmichael1/programs/scorecord/example.nim(9, 14) template/generic instantiation of `redirect` from here
/home/reesmichael1/.nimble/pkgs/jester-0.5.0/jester.nim(592, 11) Error: undeclared identifier: 'allRoutes'

If I change the redirect to a resp, the sample successfully compiles.

I haven't dug into it enough to be certain, but it seems likely that this is due to the changes in #265. Adding halt = false to the redirect call makes no difference.

mildred commented 3 years ago

I have the same issue with my nimnews package. The code is rather simple:

proc root*(req: Request): Future[ResponseData] {.async.} =
  block route:
    redirect("/group/")
ericarthurc commented 3 years ago

I am having similar issues with Jester 0.5.0. When I use the macro routes: if I add the error block I can't use redirect

routes:
  get "/":
    redirect "/blog"

  error {Http401 .. Http408}:
    redirect "/somepathhere"

The redirect in the get: block will work just fine, but the redirect in the error: block will throw Error: undeclared identifier: 'allRoutes'

Then if I move to a custom match proc like in exmaple2 I can't use redirect at all

proc match(request: Request): Future[ResponseData] {.async.} =
  block route:
    case request.pathInfo
    of "/":
      redirect "/blog"
    else:
      resp Http404, "Not found!"

The redirect in the of "/" will throw Error: undeclared identifier: 'allRoutes'

I am using: nim v1.4.8 Windows WSL Ubuntu 20.04