1602/railway-routes

How to add a filter in routes like you do in express ?

Closed this issue · 6 comments

In express, I can add a certain filter just to check if a User has been logged in or not by doing something like this :-

app.get('/posts', ensureLoggedIn(), posts.index);

How do i induce the ensureLoggedIn() behaviour using railway-routes ?

map.get('/posts', ensureLoggedIn(), posts.index);

it should work for railway routes.

On Fri, Oct 18, 2013 at 3:30 PM, Kaushik Thirthappa <
notifications@github.com> wrote:

In express, I can add a certain filter just to check if a User has been
logged in or not by doing something like this :-

app.get('/posts', ensureLoggedIn(), posts.index);

How do i induce the ensureLoggedIn() behaviour using railway-routes ?


Reply to this email directly or view it on GitHubhttps://github.com//issues/26
.

as in,

map.get('/posts', ensureLoggedIn(), 'posts#index');

This should work ? Because its not really working for me. I will have to edit my handler in this case i think.

I tried using the middleware parameter like you have in your example app on this line which works fine. But i want some filter kinda functionality which executes on every request.

btw, i am using railway-routes on an express app and not with compoundjs

and how do i use it with resources ?

map.resources('posts', ensureLoggedIn());

Even in this case, it loads as the middleware and not execute ensureLoggedIn() on every request.

Any ideas ?

1602 commented

With resources, as per example: https://github.com/anatoliychakkaev/railway-routes-example-app/blob/master/routes.js#L9
Without resources:

map.get('/posts', 'controllerName#actionName', function middleware(req, res,next) { next() });

As described here: https://github.com/1602/railway-routes/blob/master/lib/railway_routes.js#L115

Cool, thanks.