Skip to content

Instantly share code, notes, and snippets.

@deleteman
Created May 31, 2014 15:44
Show Gist options
  • Save deleteman/51bc77ae865f38fa57a5 to your computer and use it in GitHub Desktop.
Save deleteman/51bc77ae865f38fa57a5 to your computer and use it in GitHub Desktop.
Url specific pre processors on Vatican.js
//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 = //....
@cherta
Copy link

cherta commented May 31, 2014

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.

app.preprocessor(jwtCallback, ['unregister']);

@endpoint (url: /auth/unregister method: delete name: unregister)
Auth.prototype.unregister = //....

This (the endpoint naming) may be also helpful for other low level tasks.

Thanks for the super-quick feedback!
@cherta

@deleteman
Copy link
Author

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