Created
August 22, 2012 03:30
-
-
Save jshirley/3422078 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Render the login action */ | |
app.get('/login', function(req, res) { | |
res.render('login') | |
}); | |
/* Handle posting, if it fails this redirects back to /login, following POST-Redirect-GET */ | |
app.post('/login', | |
requireAuth(Y), | |
function(req, res) { | |
/** | |
If we got here, we are authenticated successfully, look in the | |
middleware for implementation details. | |
**/ | |
res.redirect('/'); | |
} | |
); | |
app.get('/', | |
// This step ensures that the user is authenticated. If not, | |
// redirect to /login | |
requireAuth(Y), | |
// This step loads each model, by sending the proper access token. | |
// These requests are guaranteed to be fast. The servers are next to each other. | |
modelLoader(Y, [ 'GoalList', 'CategoryList', 'NoteList' ]), | |
// Finally, the actual action! | |
function(req, res) { | |
res.render( | |
'index', | |
{ | |
// Pass the access token, and the initial data. | |
access_token : req.session.oauth.access_token, | |
initial_state : Y.JSON.stringify( req.models || { } ), | |
initial_page : /* render the view, using the same templates your client app does */ | |
} | |
); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment