Making several applications inside of an express app
I come from a django background, and basically, the framework allows for a
lot of modular code. I've created a simple blog engine in nodejs and
express. However, all the routes end up being in my main app.js file, or
rather app.coffee, since I used coffeescript for my nodejs applications,
which complied to javascript.
So, say this is how my routes look:
app.get('/', index.index)
app.get('/users', user.list)
app.get('/blog', blog.blogList)
app.get('/blog/:id(\\d{5})', blog.blogEntry)
Now, the problem here is that if I want to sort these by categories, then
this happens, then I would have to add another app.get function to the
same file. Code:
app.get('/blog/categores/:cat(\w+), blog.someotherview)
If I wanted to add sorting according to time, for example:
app.get('/blog/time/:year(\\d{4}), blog.someYearView)
What I would like to do is delegate everything concerning /blog to be
handled by blog.js for example. Ideally, how do I get all these routes out
of the main app.js file?
You could easily do this by using the include() method in django.
No comments:
Post a Comment