Skip to content

Commit

Permalink
First solid version of sails core. Some stuff should probably be hand…
Browse files Browse the repository at this point in the history
…led internally that isn't right now (default home, 500, 404, and 403 controller actions and views). Mappings and permissions are still kept in the config directory, which is of questionable value.
  • Loading branch information
mikermcneil committed Jul 30, 2012
1 parent e4af80d commit ba9fb16
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
38 changes: 22 additions & 16 deletions lib/common.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
// Define global configuration object
config = {};

// Module Dependencies
express = require('express');
ejs = require('ejs');
fs = require('fs');
path = require('path');
async = require('async');
Sequelize = require("sequelize");
_ = require('underscore');
Email = require("email").Email;


// Load and initialize the app
exports.lift = function liftSails (userConfig) {
loadSails(userConfig);
initSails(userConfig);
exports.load(userConfig);
exports.initialize(userConfig);
}

// Validate the userConfig parameter
Expand All @@ -16,23 +30,14 @@ function validateUserConfig (userConfig) {
else if (!userConfig.datasource) {
throw new Error ("No datasource specified!");
}
return userConfig;
}

// Load the dependencies and app-specific components
exports.load = function loadSails (userConfig) {

var config = validateUserConfig(userConfig);
validateUserConfig(userConfig);
config = _.extend(userConfig,config);

// Module Dependencies
express = require('express');
ejs = require('ejs');
fs = require('fs');
path = require('path');
async = require('async');
Sequelize = require("sequelize");
_ = require('underscore');
Email = require("email").Email;

// Connect dependency requirements
sessionStore = new express.session.MemoryStore();
Expand Down Expand Up @@ -158,11 +163,11 @@ exports.load = function loadSails (userConfig) {

// Determine whether Rigging library is in place
// to detect whether integrated Mast support should be enabled
var rigging = path.existsSync(__dirname + '/rigging');
rigging = path.existsSync(__dirname + '/rigging');

// HTTP
//var app = module.exports = express.createServer();
var app = express.createServer();
app = express.createServer();

// Configuration
// Enable JSONP
Expand Down Expand Up @@ -228,7 +233,8 @@ exports.load = function loadSails (userConfig) {
// Initialize the app (start the servers)
exports.initialize = function initSails (userConfig){

var config = validateUserConfig(userConfig);
validateUserConfig(userConfig);
config = _.extend(userConfig,config);

// Listen for websocket connections (and rejects) through socket.io
var io = require('socket.io').listen(app);
Expand Down
10 changes: 5 additions & 5 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ _.each(controllerFiles,function (controller, filename) {


// Custom mappings for specific urls
if (!path.existsSync(config.appPath+'/config/mappings') ) {
throw new Error ("No mappings file in /config!");
if (!path.existsSync(config.appPath+'/config/mappings.js') ) {
throw new Error ("No mappings file found: "+config.appPath+"/config/mappings.js");
}
var mappingConfig = require(config.appPath+'/config/mappings'),
userMappings = mappingConfig.customMappings();
Expand Down Expand Up @@ -333,10 +333,10 @@ function handleWildcardRequest (req,res,next) {


// Load user access control configuration file
if (!path.existsSync(config.appPath + '/config/permissions') ) {
throw new Error ("No permissions file in /config!");
if (!path.existsSync(config.appPath + '/config/permissions.js') ) {
throw new Error ("No permissions file found: "+config.appPath+"/config/permissions.js");
}
var permissionConfig = require(config.appPath + '/config/permissions'),
var permissionConfig = require(config.appPath + '/config/permissions.js'),
accessControlTree = _.extend(permissionConfig.defaultAccessControlTree(), permissionConfig.accessControlTree());

// Route incoming requests based on credentials
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
"lib": "lib"
},
"dependencies": {
"express": ">= 2.5.11",
"express": "= 2.5.11",
"socket.io": ">= 0.9.6",
"sequelize": "=1.5.0-beta-2",
"ejs":">=0.7.2",
"connect":"=1.8.3",
"async":">=0.1.22",
"require-all":">=0.0.4",
"email":">=0.2.5",
"node-minify":">=0.4.2"
"node-minify":">=0.4.2",
"underscore":">=1.3.3"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit ba9fb16

Please sign in to comment.