Merge branch 'staging' of github.com:FreeCodeCamp/freecodecamp into staging

This commit is contained in:
Quincy Larson
2015-06-17 20:23:01 -07:00
5 changed files with 37 additions and 43 deletions

1
.gitignore vendored
View File

@ -27,3 +27,4 @@ bower_components
main.css main.css
bundle.js bundle.js
coverage coverage
.remote-sync.json

View File

@ -7,7 +7,7 @@ Welcome to Free Code Camp's open source codebase!
======================= =======================
#Note #Note
We're currently very close to moving from express to loopback. As such, please keep in mind that the instructions here for setting up and running the project do not directly translate to the staging branch. Additionally, the file structure is quite a bit different. As always, the staging branch is the appropriate place to branch off of to fix/add something! We're currently very close to moving from Express to Loopback. As such, please keep in mind that the instructions here for setting up and running the project do not directly translate to the staging branch. Additionally, the file structure is quite a bit different. As always, the staging branch is the appropriate place to branch off of to fix/add something!
Free Code Camp is an open-source community of busy people who learn to code, then build projects for nonprofits. Free Code Camp is an open-source community of busy people who learn to code, then build projects for nonprofits.

View File

@ -78,6 +78,8 @@ gulp.task('less', function() {
.pipe(gulp.dest('./public/css/')); .pipe(gulp.dest('./public/css/'));
}); });
gulp.task('build', ['less']);
gulp.task('watch', ['less', 'serve', 'sync'], function() { gulp.task('watch', ['less', 'serve', 'sync'], function() {
gulp.watch('./public/css/*.less', ['less']); gulp.watch('./public/css/*.less', ['less']);
}); });

View File

@ -59,7 +59,7 @@
"less": "~1.7.5", "less": "~1.7.5",
"less-middleware": "~2.0.1", "less-middleware": "~2.0.1",
"lodash": "^3.9.3", "lodash": "^3.9.3",
"loopback": "^2.18.0", "loopback": "https://github.com/FreeCodeCamp/loopback.git#fix/no-password",
"loopback-boot": "^2.8.0", "loopback-boot": "^2.8.0",
"loopback-component-passport": "git://github.com/FreeCodeCamp/loopback-component-passport.git#feature/emailOptional", "loopback-component-passport": "git://github.com/FreeCodeCamp/loopback-component-passport.git#feature/emailOptional",
"loopback-connector-mongodb": "^1.10.0", "loopback-connector-mongodb": "^1.10.0",

View File

@ -2,9 +2,7 @@ require('dotenv').load();
require('pmx').init(); require('pmx').init();
// handle uncaught exceptions. Forever will restart process on shutdown // handle uncaught exceptions. Forever will restart process on shutdown
var https = require('https'), var R = require('ramda'),
sslConfig = require('./ssl-config'),
R = require('ramda'),
assign = require('lodash').assign, assign = require('lodash').assign,
loopback = require('loopback'), loopback = require('loopback'),
boot = require('loopback-boot'), boot = require('loopback-boot'),
@ -54,7 +52,9 @@ app.use(compress());
app.use(lessMiddleware(path.join(__dirname, '/public'))); app.use(lessMiddleware(path.join(__dirname, '/public')));
app.use(logger('dev')); app.use(logger('dev'));
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.urlencoded({
extended: true
}));
app.use(expressValidator({ app.use(expressValidator({
customValidators: { customValidators: {
matchRegex: function(param, regex) { matchRegex: function(param, regex) {
@ -145,8 +145,7 @@ app.use(helmet.csp({
'https://cdn.inspectlet.com/inspectlet.js', 'https://cdn.inspectlet.com/inspectlet.js',
'http://cdn.inspectlet.com/inspectlet.js' 'http://cdn.inspectlet.com/inspectlet.js'
].concat(trusted), ].concat(trusted),
'connect-src': [ 'connect-src': [].concat(trusted),
].concat(trusted),
styleSrc: [ styleSrc: [
'*.googleapis.com', '*.googleapis.com',
'*.gstatic.com' '*.gstatic.com'
@ -187,7 +186,9 @@ app.use(function (req, res, next) {
}); });
app.use( app.use(
loopback.static(path.join(__dirname, '../public'), { maxAge: 86400000 }) loopback.static(path.join(__dirname, '../public'), {
maxAge: 86400000
})
); );
boot(app, { boot(app, {
@ -224,7 +225,8 @@ var passportOptions = {
null; null;
var username = (profile.username || profile.id); var username = (profile.username || profile.id);
username = typeof username === 'string' ? username.toLowerCase() : username; username = typeof username === 'string' ? username.toLowerCase() :
username;
var password = generateKey('password'); var password = generateKey('password');
var userObj = { var userObj = {
username: username, username: username,
@ -256,7 +258,9 @@ R.keys(passportProviders).map(function(strategy) {
*/ */
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
app.use(errorHandler({ log: true })); app.use(errorHandler({
log: true
}));
} else { } else {
app.use(pmx.expressErrorHandler()); app.use(pmx.expressErrorHandler());
// error handling in production disabling eslint due to express parity rules // error handling in production disabling eslint due to express parity rules
@ -279,12 +283,16 @@ if (process.env.NODE_ENV === 'development') {
var message = 'opps! Something went wrong. Please try again later'; var message = 'opps! Something went wrong. Please try again later';
if (type === 'html') { if (type === 'html') {
req.flash('errors', { msg: message }); req.flash('errors', {
msg: message
});
return res.redirect('/'); return res.redirect('/');
// json // json
} else if (type === 'json') { } else if (type === 'json') {
res.setHeader('Content-Type', 'application/json'); res.setHeader('Content-Type', 'application/json');
return res.send({ message: message }); return res.send({
message: message
});
// plain text // plain text
} else { } else {
res.setHeader('Content-Type', 'text/plain'); res.setHeader('Content-Type', 'text/plain');
@ -297,23 +305,7 @@ if (process.env.NODE_ENV === 'development') {
* Start Express server. * Start Express server.
*/ */
var options = {
key: sslConfig.privateKey,
cert: sslConfig.certificate
};
if (process.env.NODE_ENV === 'production') {
var server = https.createServer(options, app);
console.log('https://' + process.env.HOST + ':' + process.env.PORT);
server.listen(app.get('port'), function () {
console.log(
'FreeCodeCamp server listening on port %d in %s mode',
app.get('port'),
app.get('env')
);
app.emit('started', 'https://' + process.env.HOST + ':' + app.get('port'));
});
} else {
app.listen(app.get('port'), function() { app.listen(app.get('port'), function() {
console.log( console.log(
'FreeCodeCamp server listening on port %d in %s mode', 'FreeCodeCamp server listening on port %d in %s mode',
@ -321,7 +313,6 @@ if (process.env.NODE_ENV === 'production') {
app.get('env') app.get('env')
); );
}); });
}
// start the server if `$ node server.js` // start the server if `$ node server.js`