Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Routing: the Right Way to Pass Application Data to Views and Route Names
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jeff Schwartz  
View profile  
 More options Sep 6 2012, 3:14 pm
From: Jeff Schwartz <jefftschwa...@gmail.com>
Date: Thu, 6 Sep 2012 12:14:06 -0700 (PDT)
Local: Thurs, Sep 6 2012 3:14 pm
Subject: Re: Routing: the Right Way to Pass Application Data to Views and Route Names

You can expose data and services to your routes through route-specific
middleware. A while back I wrote an article on the subject which is located
@
http://jefftschwartz.wordpress.com/2012/08/23/use-express-route-speci...
.

I use this widely in my apps. It allows me to make my apps highly
modularized while my modules remain loosely coupled.

On Saturday, September 1, 2012 11:02:01 PM UTC-4, Keith Rosenberg wrote:

> The API documentation is pretty good as a reference, but I could
> personally use a more comprehensive guide to routing in Express, or maybe
> even a generic routing standards and routing guidelines that spans across
> all server routing.

> My situation is that I have some routes in path "/routes/index.js" and
> they have dependancies on some api requires in app.js, ala

> --APP.JS--
> var core = require("/core").data;

> var app = express();
> app.locals.core = core;

> var routes = require('./routes')(app)
> ----------

> --ROUTES/INDEX.JS--
> module.exports = function(app){
>     // View list of core data
>     app.get('/core', function(req, res){
>         res.render('core', {
>         title: 'core' ,
>         core: app.locals.core
>     });
>     app.get('/' +app.locals.user.id + '&uname=' + app.locals.user.name,
> function(req, res){
>         res.render('core', {
>         title: 'core' ,
>         core: app.locals.core,
>         user: app.locals.user
>     });
> });
> --------------------

> And then, of course "/core.ejs" references all the data in core. Is
> app.locals really the right way to do this? I think this is going to get
> real messy with dynamic URLs and session-based objects being passed. I am
> just trying to have some foresight and build something that won't require a
> complete overhaul in the future. As you can see in the second route, it's
> being built dynamically based on which user is loaded in this instance of
> the application, and it's starting to get ugly.

> I saw this app.param() entry <http://expressjs.com/api.html#app.param> in
> the API and I was thinking it might be party of my solution, but I don't
> think my core understanding of routing is good enough to simply read the
> API doc and be like "Oh yeah I get it, simple". Anyone have any suggestions
> for keeping this clean, anything from generic routing guides I could read
> up on to specific examples you could share?

> Thanks much!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.