Skip to content

Commit

Permalink
Added submodules: connect, optimist, mongoose
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Nov 16, 2010
1 parent acb3161 commit ea595a0
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 19 deletions.
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "lib/mongoose"]
path = lib/mongoose
url = git://github.com/LearnBoost/mongoose.git
[submodule "lib/socket.io"]
path = lib/socket.io
url = git://github.com/LearnBoost/Socket.IO-node.git
[submodule "lib/connect"]
path = lib/connect
url = git://github.com/senchalabs/connect.git
[submodule "lib/optimist"]
path = lib/optimist
url = git://github.com/substack/node-optimist.git
10 changes: 8 additions & 2 deletions config/db.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// This file will create database connection
// And call "fn" when connection is ready
module.exports = function(fn) {
var db = {};
fn && fn(db);
var mongoose = require('../lib/mongoose/mongoose').Mongoose,
db = mongoose.connect('mongodb://localhost/mapchat');

db.mongoose = mongoose;
db.models = {};
db.on('open', function() {
fn(db)
});
};
1 change: 1 addition & 0 deletions lib/connect
Submodule connect added at 434fe8
3 changes: 1 addition & 2 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ exports.require = function(filepath, context) {
exports = {},
module = {exports: exports},
dirname = path.dirname(filepath);

fn(require, console, dirname, filepath, module, exports);

return module.exports;
}

1 change: 1 addition & 0 deletions lib/mongoose
Submodule mongoose added at 45a591
1 change: 1 addition & 0 deletions lib/optimist
Submodule optimist added at 56b2b1
1 change: 1 addition & 0 deletions lib/socket.io
Submodule socket.io added at 562053
2 changes: 1 addition & 1 deletion modules/connect.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* .init() callback
*/
exports.init = function() {
exports.init = function() {
var connect = require('connect'),
middleware = invoke('middleware', connect).array;

Expand Down
28 changes: 28 additions & 0 deletions modules/point.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Initiates point model
*/

db.mongoose.model({
properties: ['location', 'topic', 'author_id', 'updated_at'],
indexes: {
'location': '2d',
'updated_at': -1,
'author_id': 1
}
});

var Point = db.models.Point = db.model('User');

exports.routes = function(app) {
app.get('/point/:id', function(req, res) {
var point = Point.find({_id: req.params.id}).first(function(point) {
if (!point) {
res.writeHead(404);
res.end();
return;
}
res.writeHead(200);
res.write(point.toJSON());
});
});
};
14 changes: 0 additions & 14 deletions modules/test.js

This file was deleted.

3 changes: 3 additions & 0 deletions run
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env node

require.paths.unshift('lib');
require.paths.unshift('lib/connect/lib');

var argv = require('optimist').argv,
env = argv.env ? '.' + argv.env : '',
db = require('./config/db' + env),
Expand Down

0 comments on commit ea595a0

Please sign in to comment.