Skip to content

Commit

Permalink
use relative requires and update config
Browse files Browse the repository at this point in the history
  • Loading branch information
madhums committed Nov 23, 2015
1 parent b91c593 commit bbc65cf
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion config/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (fs.existsSync(envFile)) {
*/

module.exports = {
db: 'mongodb://localhost/noobjs_dev',
db: 'mongodb://localhost/noobjs_dev?replicaSet=rs0',
facebook: {
clientID: process.env.FACEBOOK_CLIENTID,
clientSecret: process.env.FACEBOOK_SECRET,
Expand Down
30 changes: 14 additions & 16 deletions config/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const mongoStore = require('connect-mongo')(session);
const flash = require('connect-flash');
const winston = require('winston');
const helpers = require('view-helpers');
const config = require('config');
const config = require('./config');
const pkg = require('../package.json');

const env = process.env.NODE_ENV || 'development';
Expand All @@ -40,15 +40,13 @@ module.exports = function (app, passport) {
app.use(express.static(config.root + '/public'));

// Use winston on production
let log;
let log = 'dev';
if (env !== 'development') {
log = {
stream: {
write: message => winston.info(message)
}
};
} else {
log = 'dev';
}

// Don't log during tests
Expand Down Expand Up @@ -77,7 +75,7 @@ module.exports = function (app, passport) {
// bodyParser should be above methodOverride
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(multer());
app.use(multer().array('image', 1));
app.use(methodOverride(function (req) {
if (req.body && typeof req.body === 'object' && '_method' in req.body) {
// look in urlencoded POST bodies and delete it
Expand All @@ -90,15 +88,6 @@ module.exports = function (app, passport) {
// CookieParser should be above session
app.use(cookieParser());
app.use(cookieSession({ secret: 'secret' }));
app.use(session({
resave: true,
saveUninitialized: true,
secret: pkg.name,
store: new mongoStore({
url: config.db,
collection : 'sessions'
})
}));

// use passport session
app.use(passport.initialize());
Expand All @@ -110,8 +99,17 @@ module.exports = function (app, passport) {
// should be declared after session and flash
app.use(helpers(pkg.name));

// adds CSRF support
if (process.env.NODE_ENV !== 'test') {
if (env !== 'test') {
app.use(session({
resave: true,
saveUninitialized: true,
secret: pkg.name,
store: new mongoStore({
url: config.db,
collection : 'sessions'
})
}));

app.use(csrf());

// This could be moved to view-helpers :-)
Expand Down
2 changes: 1 addition & 1 deletion config/passport/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const mongoose = require('mongoose');
const FacebookStrategy = require('passport-facebook').Strategy;
const config = require('config');
const config = require('../config');
const User = mongoose.model('User');

/**
Expand Down
2 changes: 1 addition & 1 deletion config/passport/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const mongoose = require('mongoose');
const GithubStrategy = require('passport-github').Strategy;
const config = require('config');
const config = require('../config');
const User = mongoose.model('User');

/**
Expand Down
2 changes: 1 addition & 1 deletion config/passport/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const mongoose = require('mongoose');
const GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
const config = require('config');
const config = require('../config');
const User = mongoose.model('User');

/**
Expand Down
2 changes: 1 addition & 1 deletion config/passport/linkedin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const mongoose = require('mongoose');
const LinkedinStrategy = require('passport-linkedin').Strategy;
const config = require('config');
const config = require('../config');
const User = mongoose.model('User');

/**
Expand Down
2 changes: 1 addition & 1 deletion config/passport/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const mongoose = require('mongoose');
const LocalStrategy = require('passport-local').Strategy;
const config = require('config');
const config = require('../config');
const User = mongoose.model('User');

/**
Expand Down
2 changes: 1 addition & 1 deletion config/passport/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const mongoose = require('mongoose');
const TwitterStrategy = require('passport-twitter').Strategy;
const config = require('config');
const config = require('../config');
const User = mongoose.model('User');

/**
Expand Down
15 changes: 11 additions & 4 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// Note: We can require users, articles and other cotrollers because we have
// set the NODE_PATH to be ./app/controllers (package.json # scripts # start)

const users = require('users');
const articles = require('articles');
const comments = require('comments');
const tags = require('tags');
const users = require('../app/controllers/users');
const articles = require('../app/controllers/articles');
const comments = require('../app/controllers/comments');
const tags = require('../app/controllers/tags');
const auth = require('./middlewares/authorization');

/**
Expand Down Expand Up @@ -122,7 +122,14 @@ module.exports = function (app, passport) {
|| (~err.message.indexOf('Cast to ObjectId failed')))) {
return next();
}

console.error(err.stack);

if (err.stack.includes('ValidationError')) {
res.status(422).render('422', { error: err.stack });
return;
}

// error page
res.status(500).render('500', { error: err.stack });
});
Expand Down

0 comments on commit bbc65cf

Please sign in to comment.