Permalink
Browse files

Initial Commit

  • Loading branch information...
0 parents commit 94887d85247fa27426081ccc93e75444042b52cc @robrighter committed Aug 30, 2010
@@ -0,0 +1,13 @@
+[submodule "lib/Socket.IO"]
+ path = lib/Socket.IO
+ url = http://github.com/LearnBoost/Socket.IO.git
+[submodule "lib/Socket.IO-node"]
+ path = lib/Socket.IO-node
+ url = http://github.com/LearnBoost/Socket.IO-node.git
+[submodule "lib/express"]
+ path = lib/express
+ url = http://github.com/visionmedia/express.git
+
+[submodule "lib/html5-boilerplate"]
+ path = lib/html5-boilerplate
+ url = http://github.com/robrighter/html5-boilerplate.git
Submodule Socket.IO added at cd30cb
Submodule Socket.IO-node added at 7b7270
Submodule express added at baa423
Submodule html5-boilerplate added at c64518
@@ -0,0 +1,72 @@
+//Setup.js created by Ben Weaver (http://gist.github.com/508314)
+
+var fs = require('fs'),
+ path = require('path');
+
+exports.app = app;
+exports.lib = lib;
+exports.ext = ext;
+exports.run = run;
+
+
+/// --- Methods
+
+var run = require;
+
+// A shortcut for adding `lib' and `ext' subfolders, then running a
+// main program.
+function app(base, main) {
+ lib(path.join(base, 'lib'));
+ ext(path.join(base, 'ext'));
+ return main ? run(path.join(base, main)) : exports;
+}
+
+// Local libraries
+function lib(folder) {
+ if (exists(folder))
+ require.paths.unshift(folder);
+ return exports;
+}
+
+// Third-party libraries
+function ext(folder) {
+ if (!exists(folder))
+ return exports;
+
+ // Some programmers refer to third-party libraries in a fully-qualified manner.
+ require.paths.unshift(folder);
+
+ fs.readdirSync(folder).forEach(function(name) {
+ var base = path.join(folder, name),
+ linked = false;
+
+ // Pure-JS packages have a `lib' folder with LIBRARY.js files in it.
+ // Packages with C++ bindings will have a `build/default' folder
+ // with LIBRARY.node files in it after running node-waf.
+ [path.join(base, '/build/default'), path.join(base, '/lib')]
+ .forEach(function(folder) {
+ if (exists(folder)) {
+ require.paths.unshift(folder);
+ linked = true;
+ }
+ });
+
+ // If neither `lib' or `build' were found, fallback to linking the
+ // folder itself.
+ if (!linked)
+ require.paths.unshift(base);
+ });
+ return exports;
+}
+
+
+/// --- Aux
+
+function exists(filename) {
+ try {
+ fs.statSync(filename);
+ return true;
+ } catch (x) {
+ return false;
+ }
+}
@@ -0,0 +1,94 @@
+//setup Dependencies
+require(__dirname + "/lib/setup").ext( __dirname + "/lib").ext( __dirname + "/lib/express/support");
+var connect = require('connect')
+ , express = require('express')
+ , sys = require('sys')
+ , io = require('Socket.IO-node')
+ , port = 8081;
+
+//Setup Express
+var server = express.createServer();
+server.configure(function(){
+ server.set('views', __dirname + '/views');
+ server.use(connect.bodyDecoder());
+ server.use(connect.staticProvider(__dirname + '/static'));
+ server.use(server.router);
+});
+
+//setup the errors
+server.error(function(err, req, res, next){
+ if (err instanceof NotFound) {
+ res.render('404.ejs', { locals: {
+ header: '#Header#'
+ ,footer: '#Footer#'
+ ,title : '404 - Not Found'
+ ,description: ''
+ ,author: ''
+ ,analyticssiteid: 'XXXXXXX'
+ } });
+ } else {
+ res.render('500.ejs', { locals: {
+ header: '#Header#'
+ ,footer: '#Footer#'
+ ,title : 'The Server Encountered an Error'
+ ,description: ''
+ ,author: ''
+ ,analyticssiteid: 'XXXXXXX'
+ ,error: err
+ } });
+ }
+});
+server.listen( port);
+
+//Setup Socket.IO
+var io = io.listen(server);
+io.on('connection', function(client){
+ console.log('Client Connected');
+ client.on('message', function(message){
+ client.broadcast(message);
+ client.send(message);
+ });
+ client.on('disconnect', function(){
+ console.log('Client Disconnected.');
+ });
+});
+
+
+///////////////////////////////////////////
+// Routes //
+///////////////////////////////////////////
+
+/////// ADD ALL YOUR ROUTES HERE /////////
+
+server.get('/', function(req,res){
+ res.render('index.ejs', {
+ locals : {
+ header: '#Header#'
+ ,footer: '#Footer#'
+ ,title : 'Page Title'
+ ,description: 'Page Description'
+ ,author: 'Your Name'
+ ,analyticssiteid: 'XXXXXXX'
+ }
+ });
+});
+
+
+//A Route for Creating a 500 Error (Useful to keep around)
+server.get('/500', function(req, res){
+ throw new Error('This is a 500 Error');
+});
+
+//The 404 Route (ALWAYS Keep this as the last route)
+server.get('/*', function(req, res){
+ throw new NotFound;
+});
+
+function NotFound(msg){
+ this.name = 'NotFound';
+ Error.call(this, msg);
+ Error.captureStackTrace(this, arguments.callee);
+}
+
+
+console.log('Listening on http://0.0.0.0:' + port );
@@ -0,0 +1,7 @@
+
+* {
+ float: none; /* Screens are not big enough to account for floats */
+ font-size: 80%; /* Slightly reducing font size to reduce need to scroll */
+ background: #fff; /* As much contrast as possible */
+ color: #000;
+}
Oops, something went wrong.

0 comments on commit 94887d8

Please sign in to comment.