Permalink
Browse files

made it easier to start using the default app.js by providing a start…

…up parameter with which you can choose between the nowjs technology or the raw socketio.
  • Loading branch information...
1 parent 5d23035 commit 25ff7f65dd440298df450a84af7f7a2a9bcba3ae @jettro committed Apr 19, 2011
Showing with 72 additions and 53 deletions.
  1. +8 −3 README
  2. +2 −2 app-nowjs.js
  3. +2 −2 app-socketio.js
  4. +46 −0 app-uniform.js
  5. +8 −45 app.js
  6. +6 −1 nowjs.js
View
11 README
@@ -6,8 +6,13 @@ The sample uses expressjs, the layout of the sample is as follows:
- views [contains the views, in my case jade templates and view files]
You can start the application in two modes:
-- app-socketio.js [is functioning and the main focus at the moment]
-- app-now.js [at the moment not a fully functional sample, will be in the near future]
-- app.js [contains the generic part of the application, this way I do not have to program the same thing for the socket.io and nowjs sample]
+- socketio [is functioning completely and the main focus at the moment]
+- nowjs [at the moment not a fully functional sample, will be in the near future]
+- app-uniform.js [contains the generic part of the application, this way I do not have to program the same thing for the socket.io and nowjs sample]
+- app.js [used to start the sample, the default is socketio, if you provide nowjs as an argument, that technology is used]
+
+Just to be sure, examples for starting the sample:
+node app.js
+node app.js nowjs
The final remark is about configuring the sample. If you want to make use of the twitter authentication you have to provide the consumer key and secret as well as the server name for the callback. There is a template for the config.json available in the config folder. Copy the file and name it as config.json.
View
4 app-nowjs.js
@@ -1,7 +1,7 @@
var NowjsApp = require('./nowjs');
var nowjsApp = new NowjsApp();
-var App = require('./app');
-var app = new App();
+var AppUniform = require('./app-uniform');
+var app = new AppUniform();
app.start(nowjsApp);
View
4 app-socketio.js
@@ -12,7 +12,7 @@
var Socketio = require('./socketio');
var socketio = new Socketio();
-var App = require('./app');
-var app = new App();
+var AppUniform = require('./app-uniform');
+var app = new AppUniform();
app.start(socketio);
View
46 app-uniform.js
@@ -0,0 +1,46 @@
+function AppUniform() {
+}
+
+var properties = require('./properties');
+var Site = require('./site');
+var Blog = require('./blog');
+
+AppUniform.prototype.start = function(chat) {
+ var pub = __dirname + '/public';
+
+ var express = require('express')
+ , app = express.createServer()
+ , blog = new Blog()
+ , site = new Site(properties);
+
+ app.configure(function() {
+ app.set('view engine', 'jade');
+ app.set('views', __dirname + '/views');
+ app.set('view options', { layout: 'layout' });
+ app.use(express.compiler({ src: pub, enable: ['sass'] }));
+ app.use(express.methodOverride());
+ app.use(express.static(pub));
+ app.use(express.logger());
+ app.use(express.bodyParser());
+ app.use(express.cookieParser());
+ app.use(express.session({ secret: "keyboard cat" }));
+ });
+
+// general
+ app.get('/', site.index);
+ app.get('/authenticate', site.authenticate);
+ app.get('/authenticated', site.authenticated);
+
+// blog
+ app.get('/blog', blog.index);
+ app.get('/blog/new', blog.blogShowForm);
+ app.post('/blog/new', blog.blogPostForm);
+
+ app.get('/chat', chat.index);
+ app.listen(process.env.VCAP_APP_PORT || 8008);
+
+ console.log('Express server started on port %s', app.address().port);
+
+ chat.init(app);
+};
+module.exports = AppUniform;
View
53 app.js
@@ -1,47 +1,10 @@
-function App() {
+var technology = process.argv[2];
+console.log("Provided argument is %s",technology);
+if (technology == "nowjs") {
+ console.log("Starting the nowjs variant of the sample");
+ require("./app-nowjs");
+} else {
+ console.log("Starting the socketio variant of the sample");
+ require("./app-socketio");
}
-var chat;
-var properties = require('./properties');
-var Site = require('./site');
-var Blog = require('./blog');
-
-App.prototype.start = function(chat) {
- var pub = __dirname + '/public';
-
- var express = require('express')
- , app = express.createServer()
- , blog = new Blog()
- , site = new Site(properties);
-
- app.configure(function() {
- app.set('view engine', 'jade');
- app.set('views', __dirname + '/views');
- app.set('view options', { layout: 'layout' });
- app.use(express.compiler({ src: pub, enable: ['sass'] }));
- app.use(express.methodOverride());
- app.use(express.static(pub));
- app.use(express.logger());
- app.use(express.bodyParser());
- app.use(express.cookieParser());
- app.use(express.session({ secret: "keyboard cat" }));
- });
-
-// general
- app.get('/', site.index);
- app.get('/authenticate', site.authenticate);
- app.get('/authenticated', site.authenticated);
-
-// blog
- app.get('/blog', blog.index);
- app.get('/blog/new', blog.blogShowForm);
- app.post('/blog/new', blog.blogPostForm);
-
- app.get('/chat', chat.index);
- app.listen(8008);
-
- console.log('Express server started on port %s', app.address().port);
-
- chat.init(app);
-};
-module.exports = App;
View
7 nowjs.js
@@ -4,7 +4,12 @@ function NowjsApp() {
// url handling
NowjsApp.prototype.index = function(req, res) {
console.log('Opening up the nowjs sample');
- res.render('now/index', {layout: 'now/layout'})
+ var loginName='';
+ if (req.session.oauth) {
+ loginName = req.session.user.name;
+ }
+
+ res.render('now/index', {layout: 'now/layout', locals:{loginName:loginName}})
};
// nowjs configuration

0 comments on commit 25ff7f6

Please sign in to comment.