Skip to content

Commit

Permalink
Serve a separate HTML page to unsupported browsers. Still needs styling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Martin committed Dec 7, 2011
1 parent 3db7ddf commit 282346e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/lib/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ exports.bundle = function (app_dir, output_path, options) {
fs.writeFileSync(path.join(build_path, 'app.html'),
bundle.generate_app_html());

fs.writeFileSync(path.join(build_path, 'unsupported.html'),
fs.readFileSync(path.join(__dirname, "unsupported.html")));

fs.writeFileSync(path.join(build_path, 'main.js'),
"require(require('path').join(__dirname, 'server/server.js'));\n");

Expand Down
9 changes: 9 additions & 0 deletions app/lib/unsupported.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
</head>
<body>
This browser is unsupported. XXX make this page nice!
</body>
</html>
13 changes: 12 additions & 1 deletion app/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var argv = require('optimist').argv;
var mime = require('mime');
var socketio = require('socket.io');
var handlebars = require('handlebars');
var useragent = require('useragent');

// this is a copy of underscore that will be shipped just for use by
// this file, server.js.
Expand All @@ -37,6 +38,11 @@ var init_keepalive = function () {
}, 3000);
};

var supported_browser = function (user_agent) {
var agent = useragent.lookup(user_agent);
return !(agent.family === 'IE' && agent.major <= '7');
};

var run = function (bundle_dir) {
var bundle_dir = path.join(__dirname, '..');

Expand All @@ -50,9 +56,14 @@ var run = function (bundle_dir) {
var app = connect.createServer();
app.use(gzip.gzip());
app.use(connect.static(path.join(bundle_dir, 'static')));

var app_html = fs.readFileSync(path.join(bundle_dir, 'app.html'));
var unsupported_html = fs.readFileSync(path.join(bundle_dir, 'unsupported.html'));
app.use(function (req, res) {
res.write(app_html);
if (supported_browser(req.headers['user-agent']))
res.write(app_html);
else
res.write(unsupported_html);
res.end();
});

Expand Down

0 comments on commit 282346e

Please sign in to comment.