-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Before/after middlewares called on every route. #69
Comments
I pushed a fix for this here 01f6b8d 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 One thing to note is that I needed to upgrade to Janet 1.11.3 from 1.10.0. Otherwise I got this error:
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!
The text was updated successfully, but these errors were encountered: