Alternative route syntax #1501

Closed
rauchg opened this Issue Feb 6, 2013 · 10 comments

Comments

Projects
None yet
4 participants
Contributor

rauchg commented Feb 6, 2013

To avoid routes that grow too much horizontally, and to make it easier to visualize / add / remove middleware:

app.get('/woot')
.use(express.compress())
.use(user.load())
.use(function(req, res, next){
  res.send(200);
});
Contributor

rauchg commented Feb 6, 2013

Also to easily introduce conditional middleware.

Contributor

rauchg commented Feb 6, 2013

var route = app.get('/');

if ('production' == env) {
  route.use(express.auth());
}

route.use(function(req, res, next){
  next();
});
Owner

tj commented Feb 6, 2013

we should have dumped chainable methods in 3.x, totally forgot since we dont chain, we're screwed for this ATM

Owner

tj commented Feb 6, 2013

however we can still do stuff like:

app.get('/woot', express.compress())
app.get('/woot', user.load())
app.get('/woot', handler)
Member

jonathanong commented Feb 18, 2013

For my pull request, you can do:

var route = app.subroute('/')

if ('production' == env) {
  route.get(express.auth());
}

route.get(function(req, res, next){
  next();
});
Contributor

defunctzombie commented Nov 20, 2013

@jonathanong can we instead do

var route = app.route('/');

Or is the route method call already taken? No point in calling it a subroute. This would be quite nice actually for RESTFUL apis that repeat routes but change method names.

Member

jonathanong commented Nov 20, 2013

yeah i tried doing this before, but route is taken and i didn't want to change the API around. this is what i'm doing for my own koa router: https://github.com/koajs/trie-router

i don't remember what .route does, but if we can get rid of it, i'm +1 for app.route(path)[verb](middleware)

Contributor

defunctzombie commented Nov 21, 2013

I don't see an app.route call...maybe my font is too small or I am getting blind in my old age.

Member

jonathanong commented Nov 21, 2013

i just remember it was defined. i don't know what it was.

Contributor

defunctzombie commented Nov 21, 2013

There is Router.route private api
On Nov 20, 2013 8:40 PM, "Jonathan Ong" notifications@github.com wrote:

i just remember it was defined. i don't know what it was.


Reply to this email directly or view it on GitHubhttps://github.com/visionmedia/express/issues/1501#issuecomment-28950995
.

defunctzombie was assigned Dec 4, 2013

defunctzombie was unassigned by rauchg Jul 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment