Skip to content

Commit

Permalink
Working through the errors thrown by buildbug
Browse files Browse the repository at this point in the history
Moving Routes, ExpressRoute, and SocketRoute to bugjs bugroutes project

[airbug/airbug#89] Airbug. Airbug MVP Part I: Chat Basics
  • Loading branch information
sungchoi committed May 13, 2013
1 parent b02aa25 commit 8b52596
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 110 deletions.
12 changes: 7 additions & 5 deletions buildbug.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ buildProperties({
main: "./lib/AirBugServer.js",
dependencies: {
bugpack: "https://s3.amazonaws.com/airbug/bugpack-0.0.5.tgz",
connect: "2.x",
express: "3.0.x",
mu2express: "0.0.x",
"mongodb": ">=1.2.11",
Expand All @@ -55,10 +56,11 @@ buildProperties({
sourcePaths: [
"./projects/airbugserver/js/src",
'../bugjs/projects/annotate/js/src',
'../bugjs/projects/bugboil/js/src',
'../bugjs/projects/bugflow/js/src',
'../bugjs/projects/bugfs/js/src',
'../bugjs/projects/bugioc/js/src',
'../bugjs/projects/bugjs/js/src',
'../bugjs/projects/bugroutes/js/src',
'../bugjs/projects/bugtrace/js/src',
'../bugunit/projects/bugunit/js/src'
// "../bugjs/projects/clientjs/js/src"
Expand All @@ -68,7 +70,8 @@ buildProperties({
"../bugunit/projects/bugunit/js/scripts"
],
testPaths: [
"../bugjs/projects/bugjs/js/test"
"../bugjs/projects/bugjs/js/test",
'../bugjs/projects/bugroutes/js/test'
],

//TODO BRN: These static paths are temporary until we get the client js server working.
Expand Down Expand Up @@ -150,7 +153,6 @@ buildProperties({
sourcePaths: [
'../bugjs/projects/annotate/js/src',
'../bugjs/projects/bugjs/js/src',
'../bugjs/projects/bugboil/js/src',
'../bugjs/projects/bugflow/js/src',
'../bugjs/projects/bugfs/js/src',
'../bugjs/projects/bugtrace/js/src',
Expand Down Expand Up @@ -247,7 +249,7 @@ buildTarget('local').buildFlow(
packageVersion: buildProject.getProperty("server.packageJson.version")
}
}),
/*targetTask('startNodeModuleTests', {
targetTask('startNodeModuleTests', {
init: function(task, buildProject, properties) {
var packedNodePackage = nodejs.findPackedNodePackage(
buildProject.getProperty("server.packageJson.name"),
Expand All @@ -257,7 +259,7 @@ buildTarget('local').buildFlow(
modulePath: packedNodePackage.getFilePath()
});
}
}),*/
}),
targetTask("s3EnsureBucket", {
properties: {
bucket: buildProject.getProperty("local-bucket")
Expand Down
2 changes: 1 addition & 1 deletion projects/airbugserver/js/src/AirBugApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ var AirBugApplication = Class.extend(Obj, {
// Exports
//-------------------------------------------------------------------------------

bugpack.export('airbug.AirBugApplication', AirBugApplication);
bugpack.export('airbugserver.AirBugApplication', AirBugApplication);
74 changes: 64 additions & 10 deletions projects/airbugserver/js/src/AirBugConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ var AirBugConfiguration = Class.extend(Obj, {
* @type {AirBugServer}
*/
this._airBugServer = null;

/**
* @private
* @type {{
* port: number,
* mongoDbIp: string
* }}
*/
this._config = null;

/**
* @type {string}
*/
this._configFilePath = null;
},


Expand All @@ -100,11 +114,6 @@ var AirBugConfiguration = Class.extend(Obj, {
this._airBugServer.start();
},


//-------------------------------------------------------------------------------
// Configuration Methods
//-------------------------------------------------------------------------------

/**
* @return {AirBugServer}
*/
Expand All @@ -120,6 +129,12 @@ var AirBugConfiguration = Class.extend(Obj, {
return new ChatMessagesApi();
},

config: function(){
this._configFilePath = path.resolve(__dirname, '../config.json');
this._config = this.loadConfig(this.configFilePath);
return this._config;
},

/**
* @return {ConversationsApi}
*/
Expand All @@ -131,7 +146,7 @@ var AirBugConfiguration = Class.extend(Obj, {
* @return {ExpressServer}
*/
expressApp: function() {
return new ExpressApp();
return new ExpressApp().initialize();
},

/**
Expand All @@ -148,6 +163,9 @@ var AirBugConfiguration = Class.extend(Obj, {
return new ExpressServer();
},

/**
* @return {Mongoose}
*/
mongoose: function(){
return mongoose;
},
Expand Down Expand Up @@ -189,6 +207,40 @@ var AirBugConfiguration = Class.extend(Obj, {
*/
usersApi: function(){
return new UsersApi();
},

//-------------------------------------------------------------------------------
// Private Methods
//-------------------------------------------------------------------------------

/*
* @private
* @param {?string=} configPath
* @return {{
* port: number,
* mongoDbIp: string
* }}
**/
loadConfig: function(configPath){
var config;
var defaults = {
port: 8000,
mongoDbIp: "localhost"
};

if (BugFs.existsSync(configPath)) {
try {
config = JSON.parse(BugFs.readFileSync(configPath, 'utf8'));
} catch(error) {
console.log(configPath, "could not be parsed. Invalid JSON.");
console.log(AirBugServer, "config set to defaults.");
return defaults;
} finally {
return config;
}
} else {
return defaults;
}
}
});

Expand All @@ -212,6 +264,7 @@ annotate(AirBugServerConfiguration).with(
//-------------------------------------------------------------------------------
module("airBugServer")
.properties([
property("config").ref("config"),
property("expressServer").ref("expressServer"),
property("mongoose").ref("mongoose"),
property("socketManager").ref("socketManager")
Expand All @@ -220,20 +273,21 @@ annotate(AirBugServerConfiguration).with(
//-------------------------------------------------------------------------------
// Express
//-------------------------------------------------------------------------------
module("expressApp"),
module("expressRoutes"),
module("expressServer")
module("expressApp")
.properties([
property("config").ref("config"),
property("expressRoutes").re("expressRoutes"),
property("sessionStore").ref("sessionStore")
]),
module("expressRoutes"),
module("expressServer"),

//-------------------------------------------------------------------------------
// Sockets
//-------------------------------------------------------------------------------
module("socketManager")
.properties([
property("server").ref("expressServer"),
// property("socketIoManager").ref("socketIoManager"),
property("socketsMap").ref("socketsMap")
]),
module("socketsMap"),
Expand Down
52 changes: 35 additions & 17 deletions projects/airbugserver/js/src/AirBugServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var path = require('path');
//-------------------------------------------------------------------------------

var BugFs = bugpack.require('bugfs.BugFs');
// var Map = bugpack.require('Map');
var ExpressServer = bugpack.require('airbugserver.ExpressServer');
var SocketManager = bugpack.require('airbugserver.SocketManager');

Expand All @@ -59,50 +58,64 @@ var AirBugServer = Class.extend(Obj, {
// Variables
//-------------------------------------------------------------------------------

/*
* @type {{
* port: number,
* mongoDbIp: string
* }}
**/
this.config = null;

/*
* @type {ExpressServer}
**/
this.expressServer = null;
this.expressServer = null;

/*
* @type {mongoose}
* @type {Mongoose}
**/
this.mongoose = null;
this.mongoose = null;

/*
* @type {SocketManager}
**/
this.socketManager = null;
this.socketManager = null;

}

//-------------------------------------------------------------------------------
// Public Methods
//-------------------------------------------------------------------------------

/*
**/
start: function() {

var configPath = path.resolve(__dirname, '../config.json');
var config = this.loadConfig(configPath);
var expressServer = this.expressServer.start();
var mongoose = this.mongoose;
var socketManager = this.socketManager.initialize(expressServer);
var cookieParser = expressServer.getCookieParser();
var sessionStore = expressServer.getSessionStore();
var sessionKey = expressServer.getSessionKey();

socketManager.enablesockets(cookieParser, sessionStore, sessionKey);

var configPath = path.resolve(__dirname, '../config.json');
var config = {
port: 8000,
mongoDbIp: "localhost"
};

if (BugFs.existsSync(configPath)) {
config = JSON.parse(BugFs.readFileSync(configPath, 'utf8'));
}
//-------------------------------------------------------------------------------
// Connect to MongoDB
//-------------------------------------------------------------------------------

mongoose.connect('mongodb://' + config.mongoDbIp + '/airbug');

//-------------------------------------------------------------------------------
// Enable Sockets
//-------------------------------------------------------------------------------

socketManager.enablesockets(cookieParser, sessionStore, sessionKey);

//-------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------

//var clientJSServer = new ClientJSServer(app);


Expand All @@ -128,11 +141,16 @@ var AirBugServer = Class.extend(Obj, {
});*/

}

//-------------------------------------------------------------------------------
// Private Methods
//-------------------------------------------------------------------------------

});


//-------------------------------------------------------------------------------
// Exports
//-------------------------------------------------------------------------------

bugpack.export('airbug.AirBugServer', AirBugServer);
bugpack.export('airbugserver.AirBugServer', AirBugServer);
Loading

0 comments on commit 8b52596

Please sign in to comment.