Closed jcreager closed 4 years ago
I pushed a fix for this here https://github.com/joy-framework/joy/commit/01f6b8d8ad3cfefc5c61890562d173b579b16870 let me know if it helped out.
I also had the requirement to show the last visited url after signing in, this is what I came up with:
(after "*" :return-to)
(defn return-to [request response]
(if (and (not= (request :uri) "/sign-in")
(get? request))
(let [session (merge (or (request :session) @{}) (or (response :session) @{}))
session (merge session {:return-to (request :uri)})]
(merge response {:session session}))
response))
Awesome, thanks @swlkr. I'll check out that hash. Also, thanks for the info on the last visited url middleware.
@swlkr 01f6b8d
appears to have fixed this issue.
One thing to note is that I needed to upgrade to Janet 1.11.3 from 1.10.0. Otherwise I got this error:
compile error: unknown symbol any? on line 186, column 19 while compiling /usr/local/Cellar/janet/1.10.0/lib/janet/joy/router.janet
any?
was added in 1.11.0.
I'm going to close this issue. Thanks for this fix!
Ah yes, we’re at the bleeding edge here in joy land haha
I’m going to mention which version of janet joy is compatible with on the readme
I like the idea of the new before/after middlewares in 0.9. However, it looks like they are called every route.
Version
Steps to reproduce
main.janet
joy server
curl localhost:9001
Expected Result
The middleware for
/foo/*
is not invoked.Actual Result
The middleware for
/foo/*
is invoked on/
.More info
I believe the source of the issue is the
wildcard-params
function.If
peg/match
is not truthy, this function returns@[]
. However,@[]
is truthy.If this function is modified to return the result of
peg/match
before/after middlewares appear to work as expected. For example:I think the intent was to keep the returned values consistent in this function. Since result of
wildcard-params
is not consumed in with-before-middleware or with-after-middleware it might be enough to have a small empty check called in thewhen-let
binding of those functions.This probably isn't as elegant as what you are looking for but it could be something like this.
And used like:
I'm still a little new to Janet so there is a good chance this is covered in the standard library and I'm not aware of it.
If I can provide any additional info let me know. Also if I'm way of base about the intended behavior of the before/after middlewares let me know. Thanks!