Skip to content

Instantly share code, notes, and snippets.

@jshirley
Created August 22, 2012 03:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jshirley/3422078 to your computer and use it in GitHub Desktop.
Save jshirley/3422078 to your computer and use it in GitHub Desktop.
/* 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 */
}
);
}
);
{{>header}}
<div id="wrap">
<div id="app">
{{initial_page}}
</div>
</div>
<!-- YUI seed file -->
<script type="text/javascript" src="http://yui.yahooapis.com/3.6.0/build/yui/yui-min.js"></script>
<!-- client configuration -->
<script type="text/javascript" src="/scripts/bundle.js"></script>
<script type="text/javascript">
YUI().use( 'tdp-mobile', function(Y) {
/**
This sets a global X-Access-Token for all models being accessed.
This is slightly dangerous, as it should only be models talking to *my* webservices.
In my application context, they all are so I opted the unsafe but easy way.
**/
Y.ModelSync.REST.HTTP_HEADERS['X-Access-Token'] = "{{ access_token }}";
var app = new Y.TDP.MobileApp({
container : '#wrap',
viewContainer : '#app',
scrollToTop : false,
initialData : {{{ initial_state }}}
});
Y.log('created an app: ' + app);
});
</script>
{{>footer}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment