Created
May 31, 2014 15:44
-
-
Save deleteman/51bc77ae865f38fa57a5 to your computer and use it in GitHub Desktop.
Url specific pre processors on Vatican.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Current solution | |
var Vatican = require("vatican"); | |
var app = new Vatican(); | |
app.preprocessor(function(req, res, next) { | |
if(req.url.indexOf("/auth/unregister") != -1) { | |
//do the checks | |
if(error) next(error) | |
} | |
next(); | |
}); | |
//Possible solutions for 1.3 based on your question: | |
//For this solution, an array of path expressions can be passed, so the preprocessor will only be triggered when the current path matches one of the given posibilities | |
app.preprocessor(jwtCallback, ['/auth/unregister']); | |
//Another option is to have the @endpoint annotation have another option, like this: | |
//.. in your auth handler | |
@endpoint (url: /auth/unregister method: delete preprocessor: jwtCallback) | |
Auth.prototype.unregister = //.... |
I like that idea!!! Thank you for the feedback!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think both ideas are valid, my personal flavor will be the first option. I prefer to avoid having a lot of data in the annotation, otherwise I can imagine people writing java like code and solving the problems in the annotations instead of in the code.
Maybe I little tweak on that direction will be name the endpoint and reference the endpoint in the preprocessor call to avoid duplicating the url.
This (the endpoint naming) may be also helpful for other low level tasks.
Thanks for the super-quick feedback!
@cherta