Skip to content

Commit

Permalink
Up version
Browse files Browse the repository at this point in the history
  • Loading branch information
biggora committed Sep 9, 2013
1 parent b9e31fe commit 879b579
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
9 changes: 5 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node
var express = require('express'), app;
var express = require('express'), config = require('./config/configuration'), app;

process.env.PORT = config.port;

/**
* Initial bootstrapping
Expand All @@ -9,9 +11,8 @@ exports.boot = function () {
return app;
};


// allow normal node loading if appropriate
if (!module.parent) {
exports.boot().listen(3000);
console.log("Express server %s listening on port %d", express.version || '3',3000);
exports.boot().listen(process.env.PORT);
console.log("Express server %s listening on port %d", express.version || '3', process.env.PORT);
}
62 changes: 34 additions & 28 deletions app/bin/trinte.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
var fs = require('fs');
var express = require('express');
var events = require('events');
var path = require('path');
var params = require('./params');
var envConf = require('../config/environment');
var config = require('../config/configuration');
Expand Down Expand Up @@ -124,43 +125,49 @@ exports.createServer = function(options) {
return app;
};


// Bootstrap models
function bootModels(trinte) {
var Schema = require('caminte').Schema,
schema = new Schema(database.db.driver, database.db);

fs.readdir('./app/models', function(err, files) {
if (err) {
console.log(err);
}
if (!files) {
trinte.emit('models_loaded');
} else {
var count = files.length;
if (count > 0) {
files.forEach(function(file) {
bootModel(trinte, schema, file);
if (--count === 0) {
if ('function' === typeof schema.autoupdate) {
schema.autoupdate(function(err) {
console.log('Run Caminte Autoupdate DataBase!');
if(err) console.log(err);
});
schema = new Schema(database.db.driver, database.db);
var modelsDir = path.resolve(__dirname, '../app/models');
try {
fs.readdir(modelsDir, function(err, files) {
if (err) {
console.log(err);
}
if (!files) {
trinte.emit('models_loaded');
} else {
var count = files.length;
if (count > 0) {
files.forEach(function(file) {
bootModel(trinte, schema, file);
if (--count === 0) {
if ('function' === typeof schema.autoupdate) {
schema.autoupdate(function(err) {
console.log('Run Caminte Autoupdate!');
if (err)
console.log(err);
});
}
trinte.emit('models_loaded');
}
trinte.emit('models_loaded');
}
});
});
}
}
}
});
});
} catch (err) {
console.log("Error: Models dir does not found");
process.exit(1);
}
}

// simplistic model support
function bootModel(trinte, schema, file) {
if(/\.js$/i.test(file)) {
var name = file.replace(/\.js$/i, '');
trinte.models[name] = require('../app/models/' + name)(schema);// Include the mongoose file
var modelDir = path.resolve(__dirname, '../app/models');
trinte.models[name] = require(modelDir + '/' + name)(schema);// Include the mongoose file
global[name] = trinte.models[name];
}
}
Expand Down Expand Up @@ -237,8 +244,7 @@ function configureApp(trinte) {
session : req.session
});
});

// Initialize users params
require('../config/params')(app);
require(root + '/config/params')(app);
});
}

0 comments on commit 879b579

Please sign in to comment.