Skip to content

Instantly share code, notes, and snippets.

@ericf
Created April 10, 2012 01:08
Show Gist options
  • Select an option

  • Save ericf/2347731 to your computer and use it in GitHub Desktop.

Select an option

Save ericf/2347731 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Example App</title>
</head>
<body>
<h1></h1>
<script src="http://yui.yahooapis.com/3.5.0pr6/build/yui/yui-min.js"></script>
<script>
YUI().use('app-base', function (Y) {
var app = new Y.App({
// Configure the app.
});
// Handles requests for the root by updating the page heading.
app.route('/', function () {
Y.one('h1').set('text', 'Example App - Home');
});
// Handles all other requests by updating the page heading and
// displaying current path in it.
app.route('*', function (req) {
Y.one('h1').set('text', 'Example App - ' + req.path);
});
// Make sure to dispatch the current hash-based URL which was set by
// the server to our route handlers.
app.render().dispatch();
});
</script>
</body>
</html>
var server = require('express').createServer();
// Handles requests to the root path ("/") my simply sending the "shell" page
// which creates the `Y.App` instance.
server.get('/', function (req, res) {
res.sendfile('index.html');
});
// Handles all other requests by redirecting the browser back to the root path
// and tacking on URL's path as the fragment; e.g. "/foo/" => "/#/foo/".
server.get('*', function (req, res) {
res.redirect('/#' + req.url, 302);
});
server.listen(process.env.PORT || 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment