Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Configuring Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshaviv committed May 2, 2014
1 parent 14c3ce7 commit 1c7ae6e
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/controllers/core.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Module dependencies.
*/
exports.index = function(req, res) {
res.render('index.server.view.html', {
res.render('index', {
user: req.user || null
});
};
4 changes: 2 additions & 2 deletions app/routes/articles.server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* Module dependencies.
*/
var users = require('../../app/controllers/users.server.controller'),
articles = require('../../app/controllers/articles.server.controller');
var users = require('../../app/controllers/users'),
articles = require('../../app/controllers/articles');

module.exports = function(app) {
// Article Routes
Expand Down
2 changes: 1 addition & 1 deletion app/routes/core.server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module.exports = function(app) {
// Root routing
var core = require('../../app/controllers/core.server.controller');
var core = require('../../app/controllers/core');
app.route('/').get(core.index);
};
2 changes: 1 addition & 1 deletion app/routes/users.server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var passport = require('passport');

module.exports = function(app) {
// User Routes
var users = require('../../app/controllers/users.server.controller');
var users = require('../../app/controllers/users');
app.route('/users/me').get(users.me);
app.route('/users').put(users.update);
app.route('/users/password').post(users.changePassword);
Expand Down
2 changes: 1 addition & 1 deletion app/views/404.server.view.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'layout.server.view.html' %}
{% extends 'layout' %}

{% block content %}
<h1>Page Not Found</h1>
Expand Down
15 changes: 5 additions & 10 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
'use strict';

/**
* Module dependencies.
*/
var _ = require('lodash'),
glob = require('glob');

/**
* Before we begin, lets set the envrionment variable
* We'll Look for a valid NODE_ENV variable and if one cannot be found load the development NODE_ENV
* Load app configurations
*/
glob('./config/env/' + process.env.NODE_ENV + '.js', {
sync: true
}, function(err, environmentFiles) {
process.env.NODE_ENV = environmentFiles.length ? process.env.NODE_ENV : 'development';
});

// Load app configurations
module.exports = _.extend(
require('./env/all'),
require('./env/' + process.env.NODE_ENV) || {}
);

/**
* Get the modules JavaScript files
* Get files by glob patterns
*/
module.exports.getGlobbedFiles = function(globPatterns, removeRoot) {
// For context switching
Expand Down
8 changes: 4 additions & 4 deletions config/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ module.exports = function(db) {
app.set('showStackError', true);

// Set swig as the template engine
app.engine('html', consolidate[config.templateEngine]);
app.engine('server.view.html', consolidate[config.templateEngine]);

// Set views path and view engine
app.set('view engine', 'html');
app.set('view engine', 'server.view.html');
app.set('views', './app/views');

// Environment dependent middleware
Expand Down Expand Up @@ -123,14 +123,14 @@ module.exports = function(db) {
console.error(err.stack);

// Error page
res.status(500).render('500.server.view.html', {
res.status(500).render('500', {
error: err.stack
});
});

// Assume 404 since no middleware responded
app.use(function(req, res) {
res.status(404).render('404.server.view.html', {
res.status(404).render('404', {
url: req.originalUrl,
error: 'Not Found'
});
Expand Down
40 changes: 40 additions & 0 deletions config/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

/**
* Module dependencies.
*/
var glob = require('glob');

/**
* Module init function.
*/
module.exports = function() {
/**
* Before we begin, lets set the envrionment variable
* We'll Look for a valid NODE_ENV variable and if one cannot be found load the development NODE_ENV
*/
glob('./config/env/' + process.env.NODE_ENV + '.js', {
sync: true
}, function(err, environmentFiles) {
console.log();
if (!environmentFiles.length) {
if(process.env.NODE_ENV) {
console.log('\x1b[31m', 'No configuration file found for "' + process.env.NODE_ENV + '" envrionment using develpoment instead');
} else {
console.log('\x1b[31m', 'NODE_ENV is not defined! Using default develpoment envrionment');
}

process.env.NODE_ENV = 'development';
} else {
console.log('\x1b[7m', 'Application loaded using the "' + process.env.NODE_ENV + '" envrionment configuration');
}
console.log('\x1b[0m');
});

/**
* Add our server node extensions
*/
require.extensions['.server.controller.js'] = require.extensions['.js'];
require.extensions['.server.model.js'] = require.extensions['.js'];
require.extensions['.server.routes.js'] = require.extensions['.js'];
};
5 changes: 4 additions & 1 deletion config/strategies/facebook.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict';

/**
* Module dependencies.
*/
var passport = require('passport'),
url = require('url'),
FacebookStrategy = require('passport-facebook').Strategy,
config = require('../config'),
users = require('../../app/controllers/users.server.controller');
users = require('../../app/controllers/users');

module.exports = function() {
// Use facebook strategy
Expand Down
5 changes: 4 additions & 1 deletion config/strategies/google.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict';

/**
* Module dependencies.
*/
var passport = require('passport'),
url = require('url'),
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy,
config = require('../config'),
users = require('../../app/controllers/users.server.controller');
users = require('../../app/controllers/users');

module.exports = function() {
// Use google strategy
Expand Down
5 changes: 4 additions & 1 deletion config/strategies/linkedin.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict';

/**
* Module dependencies.
*/
var passport = require('passport'),
url = require('url'),
LinkedInStrategy = require('passport-linkedin').Strategy,
config = require('../config'),
users = require('../../app/controllers/users.server.controller');
users = require('../../app/controllers/users');

module.exports = function() {
// Use linkedin strategy
Expand Down
3 changes: 3 additions & 0 deletions config/strategies/local.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

/**
* Module dependencies.
*/
var passport = require('passport'),
LocalStrategy = require('passport-local').Strategy,
User = require('mongoose').model('User');
Expand Down
5 changes: 4 additions & 1 deletion config/strategies/twitter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict';

/**
* Module dependencies.
*/
var passport = require('passport'),
url = require('url'),
TwitterStrategy = require('passport-twitter').Strategy,
config = require('../config'),
users = require('../../app/controllers/users.server.controller');
users = require('../../app/controllers/users');

module.exports = function() {
// Use twitter strategy
Expand Down
4 changes: 2 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Module dependencies.
*/
var config = require('./config/config'),
var init = require('./config/init')(),
config = require('./config/config'),
mongoose = require('mongoose');

/**
Expand All @@ -26,5 +27,4 @@ app.listen(config.port);
exports = module.exports = app;

// Logging initialization
console.log('Using the "' + process.env.NODE_ENV + '" envrionment file');
console.log('MEAN.JS application started on port ' + config.port);

0 comments on commit 1c7ae6e

Please sign in to comment.