Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added mongoose-get and mers to dependencies

  • Loading branch information...
commit 64c95c22ed7000cd449f155bfcf2bd2d78308bf1 1 parent b8b7f54
@debounce debounce authored
View
7 index.js
@@ -5,6 +5,8 @@ var MongoStore = require('connect-mongodb');
var routes = require('./routes');
var conf = require('./conf.js');
var util = require('./util.js');
+var models = require('./models');
+var rest = require('./modules/rest.js');
var app = module.exports = express.createServer();
@@ -54,6 +56,11 @@ app.configure(conf.PRODUCTION, function () {
});
+// add routes
+routes(app);
+rest(app);
+
+
// start http server
app.listen(conf.http.port, conf.http.host, function () {
util.log('info', 'Express server started', {
View
4 models/database.json
@@ -0,0 +1,4 @@
+{
+ "models": {
+ }
+}
View
4 models/db.json
@@ -1,4 +0,0 @@
-{
- "models": [],
- "relations": {}
-}
View
9 models/index.js
@@ -0,0 +1,9 @@
+var mongoose = require('mongoose');
+var mongooseTypes = require('mongoose-types');
+
+var conf = require('./../conf.js');
+
+var connection = mongoose.connect(conf.mongo.url);
+
+// public api
+exports.connection = connection;
View
13 modules/rest.js
@@ -0,0 +1,13 @@
+var mongoose = require('mongoose');
+var mers = require('mers');
+
+
+var rest = function (app, options) {
+ app.use('/api/v1', mers({
+ 'mongoose': mongoose
+ }).rest());
+};
+
+
+// public api
+module.exports = rest;
View
8 package.json
@@ -17,11 +17,15 @@
"express": "~2.5.11",
"connect": "~2.3.5",
"winston": "~0.6.1",
- "express-session-mongo": "~0.0.1"
+ "express-session-mongo": "~0.0.1",
+ "mongoose": "~2.7.1",
+ "mongoose-types": "~1.0.3",
+ "mers": "~0.3.8",
+ "mongoose-gen": "~0.0.1"
},
"devDependencies": {},
"optionalDependencies": {},
"engines": {
- "node": "*"
+ "node": "0.6"
}
}
View
3  routes/index.js
@@ -1 +1,4 @@
+var routes = function (app) {};
+
+module.exports = routes;
View
59 util.js
@@ -21,6 +21,65 @@ var log = function () {
return winston.log.apply(winston, arguments);
};
+var merge = function () {
+ var result = {},
+ args = Array.prototype.slice.call(arguments),
+ mergeRecursive = function (obj1, obj2) {
+ for (var p in obj2) {
+ try {
+ if ( obj2[p].constructor==Object ) {
+ obj1[p] = mergeRecursive(obj1[p], obj2[p]);
+ }
+ else {
+ obj1[p] = obj2[p];
+ }
+ }
+ catch(e) {
+ obj1[p] = obj2[p];
+ }
+ }
+ return obj1;
+ };
+
+ args.forEach( function (obj) {
+ mergeRecursive(result, obj);
+ });
+ return result;
+};
+
+
+var pluralize = function (str) {
+ var rules = [
+ [/(m)an$/gi, '$1en'],
+ [/(pe)rson$/gi, '$1ople'],
+ [/(child)$/gi, '$1ren'],
+ [/^(ox)$/gi, '$1en'],
+ [/(ax|test)is$/gi, '$1es'],
+ [/(octop|vir)us$/gi, '$1i'],
+ [/(alias|status)$/gi, '$1es'],
+ [/(bu)s$/gi, '$1ses'],
+ [/(buffal|tomat|potat)o$/gi, '$1oes'],
+ [/([ti])um$/gi, '$1a'],
+ [/sis$/gi, 'ses'],
+ [/(?:([^f])fe|([lr])f)$/gi, '$1$2ves'],
+ [/(hive)$/gi, '$1s'],
+ [/([^aeiouy]|qu)y$/gi, '$1ies'],
+ [/(x|ch|ss|sh)$/gi, '$1es'],
+ [/(matr|vert|ind)ix|ex$/gi, '$1ices'],
+ [/([m|l])ouse$/gi, '$1ice'],
+ [/(quiz)$/gi, '$1zes'],
+ [/s$/gi, 's'],
+ [/$/gi, 's']
+ ];
+
+ var found = rules.filter( function (rule) {
+ return str.match(rule[0]);
+ });
+ if (found[0]) return str.replace(found[0][0], found[0][1]);
+ else return str;
+};
// public api
exports.log = log;
+exports.merge = merge;
+exports.pluralize = pluralize;
Please sign in to comment.
Something went wrong with that request. Please try again.