Work on bonfire and make better .jshintrc files
This commit is contained in:
183
app.js
183
app.js
@ -24,8 +24,8 @@ var express = require('express'),
|
||||
connectAssets = require('connect-assets'),
|
||||
|
||||
/**
|
||||
* Controllers (route handlers).
|
||||
*/
|
||||
* Controllers (route handlers).
|
||||
*/
|
||||
homeController = require('./controllers/home'),
|
||||
challengesController = require('./controllers/challenges'),
|
||||
resourcesController = require('./controllers/resources'),
|
||||
@ -34,13 +34,13 @@ var express = require('express'),
|
||||
bonfireController = require('./controllers/bonfire'),
|
||||
|
||||
/**
|
||||
* User model
|
||||
*/
|
||||
* User model
|
||||
*/
|
||||
User = require('./models/User'),
|
||||
|
||||
/**
|
||||
* API keys and Passport configuration.
|
||||
*/
|
||||
* API keys and Passport configuration.
|
||||
*/
|
||||
secrets = require('./config/secrets'),
|
||||
passportConf = require('./config/passport');
|
||||
|
||||
@ -53,10 +53,10 @@ var app = express();
|
||||
* Connect to MongoDB.
|
||||
*/
|
||||
mongoose.connect(secrets.db);
|
||||
mongoose.connection.on('error', function() {
|
||||
console.error(
|
||||
'MongoDB Connection Error. Please make sure that MongoDB is running.'
|
||||
);
|
||||
mongoose.connection.on('error', function () {
|
||||
console.error(
|
||||
'MongoDB Connection Error. Please make sure that MongoDB is running.'
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
@ -68,20 +68,20 @@ app.set('views', path.join(__dirname, 'views'));
|
||||
app.set('view engine', 'jade');
|
||||
app.use(compress());
|
||||
var oneYear = 31557600000;
|
||||
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
|
||||
app.use(express.static(__dirname + '/public', {maxAge: oneYear}));
|
||||
app.use(connectAssets({
|
||||
paths: [
|
||||
path.join(__dirname, 'public/css'),
|
||||
path.join(__dirname, 'public/js')
|
||||
path.join(__dirname, 'public/css'),
|
||||
path.join(__dirname, 'public/js')
|
||||
],
|
||||
helperContext: app.locals
|
||||
}));
|
||||
app.use(logger('dev'));
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
app.use(bodyParser.urlencoded({extended: true}));
|
||||
app.use(expressValidator({
|
||||
customValidators: {
|
||||
matchRegex: function(param, regex) {
|
||||
matchRegex: function (param, regex) {
|
||||
return regex.test(param);
|
||||
}
|
||||
}
|
||||
@ -137,50 +137,50 @@ app.use(helmet.contentSecurityPolicy({
|
||||
defaultSrc: trusted,
|
||||
scriptSrc: ['*.optimizely.com', '*.aspnetcdn.com'].concat(trusted),
|
||||
'connect-src': [
|
||||
'ws://*.rafflecopter.com',
|
||||
'wss://*.rafflecopter.com',
|
||||
'https://*.rafflecopter.com',
|
||||
'ws://www.freecodecamp.com',
|
||||
'http://www.freecodecamp.com'
|
||||
'ws://*.rafflecopter.com',
|
||||
'wss://*.rafflecopter.com',
|
||||
'https://*.rafflecopter.com',
|
||||
'ws://www.freecodecamp.com',
|
||||
'http://www.freecodecamp.com'
|
||||
].concat(trusted),
|
||||
styleSrc: trusted,
|
||||
imgSrc: [
|
||||
'*.evernote.com',
|
||||
'*.amazonaws.com',
|
||||
'data:',
|
||||
'*.licdn.com',
|
||||
'*.gravatar.com',
|
||||
'*.youtube.com',
|
||||
'*.akamaihd.net',
|
||||
'graph.facebook.com',
|
||||
'*.githubusercontent.com',
|
||||
'*.googleusercontent.com',
|
||||
'*' /* allow all input since we have user submitted images for public profile*/
|
||||
'*.evernote.com',
|
||||
'*.amazonaws.com',
|
||||
'data:',
|
||||
'*.licdn.com',
|
||||
'*.gravatar.com',
|
||||
'*.youtube.com',
|
||||
'*.akamaihd.net',
|
||||
'graph.facebook.com',
|
||||
'*.githubusercontent.com',
|
||||
'*.googleusercontent.com',
|
||||
'*' /* allow all input since we have user submitted images for public profile*/
|
||||
].concat(trusted),
|
||||
fontSrc: ['*.googleapis.com'].concat(trusted),
|
||||
mediaSrc: [
|
||||
'*.amazonaws.com',
|
||||
'*.twitter.com'
|
||||
'*.amazonaws.com',
|
||||
'*.twitter.com'
|
||||
].concat(trusted),
|
||||
frameSrc: [
|
||||
'*.gitter.im',
|
||||
'*.vimeo.com',
|
||||
'*.twitter.com',
|
||||
'*.rafflecopter.com',
|
||||
'*.youtube.com'
|
||||
'*.gitter.im',
|
||||
'*.vimeo.com',
|
||||
'*.twitter.com',
|
||||
'*.rafflecopter.com',
|
||||
'*.youtube.com'
|
||||
].concat(trusted),
|
||||
reportOnly: false, // set to true if you only want to report errors
|
||||
setAllHeaders: false, // set to true if you want to set all headers
|
||||
safari5: false // set to true if you want to force buggy CSP in Safari 5
|
||||
}));
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
app.use(function (req, res, next) {
|
||||
// Make user object available in templates.
|
||||
res.locals.user = req.user;
|
||||
next();
|
||||
});
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
app.use(function (req, res, next) {
|
||||
// Remember original destination before login.
|
||||
var path = req.path.split('/')[1];
|
||||
if (/auth|login|logout|signup|fonts|favicon/i.test(path)) {
|
||||
@ -191,7 +191,7 @@ app.use(function(req, res, next) {
|
||||
});
|
||||
|
||||
app.use(
|
||||
express.static(path.join(__dirname, 'public'), { maxAge: 31557600000 })
|
||||
express.static(path.join(__dirname, 'public'), {maxAge: 31557600000})
|
||||
);
|
||||
|
||||
/**
|
||||
@ -200,8 +200,8 @@ app.use(
|
||||
app.get('/', homeController.index);
|
||||
|
||||
app.get(
|
||||
'/resources/interview-questions',
|
||||
resourcesController.interviewQuestions);
|
||||
'/resources/interview-questions',
|
||||
resourcesController.interviewQuestions);
|
||||
app.get('/learn-to-code', resourcesController.learnToCode);
|
||||
app.get('/privacy', resourcesController.privacy);
|
||||
app.get('/jquery-exercises', resourcesController.jqueryExercises);
|
||||
@ -215,16 +215,16 @@ app.get('/control-shortcuts', resourcesController.deployAWebsite);
|
||||
app.get('/stats', resourcesController.stats);
|
||||
|
||||
app.get(
|
||||
'/pair-program-with-team-viewer',
|
||||
resourcesController.pairProgramWithTeamViewer
|
||||
'/pair-program-with-team-viewer',
|
||||
resourcesController.pairProgramWithTeamViewer
|
||||
);
|
||||
app.get(
|
||||
'/done-with-first-100-hours',
|
||||
resourcesController.doneWithFirst100Hours
|
||||
'/done-with-first-100-hours',
|
||||
resourcesController.doneWithFirst100Hours
|
||||
);
|
||||
app.get(
|
||||
'/programmer-interview-questions-app',
|
||||
resourcesController.programmerInterviewQuestionsApp
|
||||
'/programmer-interview-questions-app',
|
||||
resourcesController.programmerInterviewQuestionsApp
|
||||
);
|
||||
|
||||
app.get('/about', resourcesController.about);
|
||||
@ -244,9 +244,9 @@ app.post('/nonprofits', contactController.postContact);
|
||||
|
||||
// # Protected routes, user must be logged in.
|
||||
app.post(
|
||||
'/update-progress',
|
||||
passportConf.isAuthenticated,
|
||||
userController.updateProgress
|
||||
'/update-progress',
|
||||
passportConf.isAuthenticated,
|
||||
userController.updateProgress
|
||||
);
|
||||
|
||||
app.get(
|
||||
@ -274,13 +274,15 @@ app.get('/account/unlink/:provider', userController.getOauthUnlink);
|
||||
* and updates user.challengesHash & user.challengesCompleted
|
||||
*
|
||||
*/
|
||||
app.post('/completed_challenge', function(req, res) {
|
||||
app.post('/completed_challenge', function (req, res) {
|
||||
req.user.challengesHash[parseInt(req.body.challengeNumber)] =
|
||||
Math.round(+ new Date() / 1000);
|
||||
Math.round(+new Date() / 1000);
|
||||
var ch = req.user.challengesHash;
|
||||
var p = 0;
|
||||
for (var k in ch) {
|
||||
if (ch[k] > 0) { p += 1; }
|
||||
if (ch[k] > 0) {
|
||||
p += 1;
|
||||
}
|
||||
}
|
||||
req.user.points = p;
|
||||
req.user.save();
|
||||
@ -291,60 +293,60 @@ app.post('/completed_challenge', function(req, res) {
|
||||
*/
|
||||
|
||||
var passportOptions = {
|
||||
successRedirect: '/',
|
||||
failureRedirect: '/login'
|
||||
successRedirect: '/',
|
||||
failureRedirect: '/login'
|
||||
};
|
||||
|
||||
app.get('/auth/twitter', passport.authenticate('twitter'));
|
||||
app.get(
|
||||
'/auth/twitter/callback',
|
||||
passport.authenticate('twitter', {
|
||||
successRedirect: '/',
|
||||
failureRedirect: '/login'
|
||||
})
|
||||
'/auth/twitter/callback',
|
||||
passport.authenticate('twitter', {
|
||||
successRedirect: '/',
|
||||
failureRedirect: '/login'
|
||||
})
|
||||
);
|
||||
|
||||
app.get(
|
||||
'/auth/linkedin',
|
||||
passport.authenticate('linkedin', {
|
||||
state: 'SOME STATE'
|
||||
})
|
||||
'/auth/linkedin',
|
||||
passport.authenticate('linkedin', {
|
||||
state: 'SOME STATE'
|
||||
})
|
||||
);
|
||||
|
||||
app.get(
|
||||
'/auth/linkedin/callback',
|
||||
passport.authenticate('linkedin', passportOptions)
|
||||
'/auth/linkedin/callback',
|
||||
passport.authenticate('linkedin', passportOptions)
|
||||
);
|
||||
|
||||
app.get(
|
||||
'/auth/facebook',
|
||||
passport.authenticate('facebook', { scope: ['email', 'user_location'] })
|
||||
'/auth/facebook',
|
||||
passport.authenticate('facebook', {scope: ['email', 'user_location']})
|
||||
);
|
||||
|
||||
app.get(
|
||||
'/auth/facebook/callback',
|
||||
passport.authenticate('facebook', passportOptions), function(req, res) {
|
||||
res.redirect(req.session.returnTo || '/');
|
||||
}
|
||||
'/auth/facebook/callback',
|
||||
passport.authenticate('facebook', passportOptions), function (req, res) {
|
||||
res.redirect(req.session.returnTo || '/');
|
||||
}
|
||||
);
|
||||
|
||||
app.get('/auth/github', passport.authenticate('github'));
|
||||
app.get(
|
||||
'/auth/github/callback',
|
||||
passport.authenticate('github', passportOptions), function(req, res) {
|
||||
res.redirect(req.session.returnTo || '/');
|
||||
}
|
||||
'/auth/github/callback',
|
||||
passport.authenticate('github', passportOptions), function (req, res) {
|
||||
res.redirect(req.session.returnTo || '/');
|
||||
}
|
||||
);
|
||||
|
||||
app.get(
|
||||
'/auth/google',
|
||||
passport.authenticate('google', { scope: 'profile email' })
|
||||
'/auth/google',
|
||||
passport.authenticate('google', {scope: 'profile email'})
|
||||
);
|
||||
app.get(
|
||||
'/auth/google/callback',
|
||||
passport.authenticate('google', passportOptions), function(req, res) {
|
||||
res.redirect(req.session.returnTo || '/');
|
||||
}
|
||||
'/auth/google/callback',
|
||||
passport.authenticate('google', passportOptions), function (req, res) {
|
||||
res.redirect(req.session.returnTo || '/');
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
@ -352,7 +354,6 @@ app.get(
|
||||
*/
|
||||
app.get('/bonfire', bonfireController.index);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 500 Error Handler.
|
||||
@ -362,12 +363,12 @@ app.use(errorHandler());
|
||||
/**
|
||||
* Start Express server.
|
||||
*/
|
||||
app.listen(app.get('port'), function() {
|
||||
console.log(
|
||||
'FreeCodeCamp server listening on port %d in %s mode',
|
||||
app.get('port'),
|
||||
app.get('env')
|
||||
);
|
||||
app.listen(app.get('port'), function () {
|
||||
console.log(
|
||||
'FreeCodeCamp server listening on port %d in %s mode',
|
||||
app.get('port'),
|
||||
app.get('env')
|
||||
);
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
Reference in New Issue
Block a user