From 1e21d5d7aa1e722a0aeb24e6a09591fb85581605 Mon Sep 17 00:00:00 2001 From: terakilobyte Date: Wed, 29 Apr 2015 19:30:51 -0400 Subject: [PATCH 1/6] Fix some linting errors in app.js and highlight questionable code with todo comments --- app.js | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/app.js b/app.js index df9bcc4c61d..3f9c07d38b8 100755 --- a/app.js +++ b/app.js @@ -48,7 +48,7 @@ var express = require('express'), /** * Stories */ - storyController = require('./controllers/story'); + storyController = require('./controllers/story'), /** * API keys and Passport configuration. @@ -88,13 +88,15 @@ if (process.env.NODE_ENV === 'production') { if (host.match(/^www\..*/i)) { next(); } else { - res.redirect(301, "http://www." + host + originalUrl); + res.redirect(301, 'http://www.' + host + originalUrl); } }); } app.use(compress()); var oneYear = 31557600000; +// todo +// another app.use(express.static...) call app.use(express.static(__dirname + '/public', {maxAge: oneYear})); app.use(connectAssets({ paths: [ @@ -135,8 +137,10 @@ app.use(helmet.xssFilter()); app.use(helmet.noSniff()); app.use(helmet.xframe()); app.use(function(req, res, next) { - res.header("Access-Control-Allow-Origin", "*"); - res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); + res.header('Access-Control-Allow-Origin', '*'); + res.header('Access-Control-Allow-Headers', + 'Origin, X-Requested-With, Content-Type, Accept' + ); next(); }); @@ -184,7 +188,7 @@ app.use(helmet.contentSecurityPolicy({ scriptSrc: [ '*.optimizely.com', '*.aspnetcdn.com', - '*.d3js.org', + '*.d3js.org' ].concat(trusted), 'connect-src': [ 'ws://*.rafflecopter.com', @@ -204,7 +208,8 @@ app.use(helmet.contentSecurityPolicy({ 'graph.facebook.com', '*.githubusercontent.com', '*.googleusercontent.com', - '*' /* allow all input since we have user submitted images for public profile*/ + /* allow all input since we have user submitted images for public profile*/ + '*' ].concat(trusted), fontSrc: ['*.googleapis.com'].concat(trusted), mediaSrc: [ @@ -245,7 +250,8 @@ app.use(function (req, res, next) { app.use( express.static(path.join(__dirname, 'public'), {maxAge: 31557600000}) ); - +// todo +// why are there two express.static declarations? app.use(express.static(__dirname + '/public', { maxAge: 86400000 })); /** @@ -264,13 +270,15 @@ app.get('/twitch', resourcesController.twitch); // Agile Project Manager Onboarding -app.get('/pmi-acp-agile-project-managers', resourcesController.agileProjectManagers); +app.get('/pmi-acp-agile-project-managers', + resourcesController.agileProjectManagers); app.get('/agile', function(req, res) { res.redirect(301, '/pmi-acp-agile-project-managers'); }); -app.get('/pmi-acp-agile-project-managers-form', resourcesController.agileProjectManagersForm); +app.get('/pmi-acp-agile-project-managers-form', + resourcesController.agileProjectManagersForm); // Nonprofit Onboarding @@ -278,8 +286,6 @@ app.get('/nonprofits', resourcesController.nonprofits); app.get('/nonprofits-form', resourcesController.nonprofitsForm); - - app.get('/map', challengeMapController.challengeMap); app.get('/live-pair-programming', function(req, res) { @@ -532,7 +538,9 @@ app.get('/api/trello', resourcesController.trelloCalls); * Bonfire related routes */ -app.get('/field-guide/getFieldGuideList', fieldGuideController.showAllFieldGuides); +app.get('/field-guide/getFieldGuideList', + fieldGuideController.showAllFieldGuides + ); app.get('/playground', bonfireController.index); @@ -562,7 +570,9 @@ app.post('/completed-bonfire/', bonfireController.completedBonfire); */ -app.get('/field-guide/:fieldGuideName', fieldGuideController.returnIndividualFieldGuide); +app.get('/field-guide/:fieldGuideName', + fieldGuideController.returnIndividualFieldGuide + ); app.get('/field-guide/', fieldGuideController.returnNextFieldGuide); @@ -586,9 +596,13 @@ app.post('/completed-zipline-or-basejump', coursewareController.completedZiplineOrBasejump); // Unique Check API route -app.get('/api/checkUniqueUsername/:username', userController.checkUniqueUsername); +app.get('/api/checkUniqueUsername/:username', + userController.checkUniqueUsername + ); -app.get('/api/checkExistingUsername/:username', userController.checkExistingUsername); +app.get('/api/checkExistingUsername/:username', + userController.checkExistingUsername + ); app.get('/api/checkUniqueEmail/:email', userController.checkUniqueEmail); From 55afd8518cddaa6f6437206abd4baea25a6f8588 Mon Sep 17 00:00:00 2001 From: terakilobyte Date: Wed, 29 Apr 2015 20:55:47 -0400 Subject: [PATCH 2/6] Add missing semi-colon --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 3f9c07d38b8..397bc22c347 100755 --- a/app.js +++ b/app.js @@ -414,7 +414,7 @@ app.get('/api/slack', function(req, res) { }); return res.redirect('back'); } - }) + }); } else { req.flash('notice', { msg: "Before we can send your Slack invite, we need your email address. Please update your profile information here." From a9b2e546decebbc1356bea396a2f2000ceb2532b Mon Sep 17 00:00:00 2001 From: terakilobyte Date: Fri, 1 May 2015 16:33:49 -0400 Subject: [PATCH 3/6] Fix twitter link on bonfire --- views/bonfire/show.jade | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/views/bonfire/show.jade b/views/bonfire/show.jade index 5e7f6202249..e252eb6a5a9 100644 --- a/views/bonfire/show.jade +++ b/views/bonfire/show.jade @@ -132,7 +132,9 @@ block content - if (user.progressTimestamps.length > 2) - a.animated.fadeIn.btn.btn-lg.btn-block.btn-twitter(target="_blank") + a.animated.fadeIn.btn.btn-lg.btn-block.btn-twitter(href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20Bonfire:%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/bonfires/#{dashedName}&hashtags=LearnToCode, JavaScript" target="_blank") + i.fa.fa-twitter   +arget="_blank") i.fa.fa-twitter   = phrase - else From 1347a8ba30b0cb78d407a07c443cd438325b6296 Mon Sep 17 00:00:00 2001 From: terakilobyte Date: Fri, 1 May 2015 16:34:07 -0400 Subject: [PATCH 4/6] Use forcedomain express middleware --- app.js | 13 ++++--------- package.json | 1 + 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index a5a1459c4d3..33c3e6ee0a0 100755 --- a/app.js +++ b/app.js @@ -32,6 +32,7 @@ var express = require('express'), expressValidator = require('express-validator'), connectAssets = require('connect-assets'), request = require('request'), + forceDomain = require('forcedomain'), /** * Controllers (route handlers). @@ -82,15 +83,9 @@ app.set('view engine', 'jade'); if (process.env.NODE_ENV === 'production') { - app.all(/.*/, function (req, res, next) { - var host = req.header('host'); - var originalUrl = req['originalUrl']; - if (host.match(/^www\..*/i)) { - next(); - } else { - res.redirect(301, 'http://www.' + host + originalUrl); - } - }); + app.use(forceDomain({ + hostname: 'www.freecodecamp.com' + })); } app.use(compress()); diff --git a/package.json b/package.json index 791058bf8cc..7112641f862 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "express-session": "^1.9.2", "express-validator": "^2.8.0", "font-awesome": "^4.3.0", + "forcedomain": "^0.4.0", "forever": "^0.14.1", "github-api": "^0.7.0", "gulp-minify-css": "^0.5.1", From 1fc35951454ed0e219e16dcc0afa73d4c021199a Mon Sep 17 00:00:00 2001 From: terakilobyte Date: Fri, 1 May 2015 16:56:09 -0400 Subject: [PATCH 5/6] Fix twitter link in bonfire/show --- views/bonfire/show.jade | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/views/bonfire/show.jade b/views/bonfire/show.jade index e252eb6a5a9..e7c5a0f9f66 100644 --- a/views/bonfire/show.jade +++ b/views/bonfire/show.jade @@ -132,9 +132,7 @@ block content - if (user.progressTimestamps.length > 2) - a.animated.fadeIn.btn.btn-lg.btn-block.btn-twitter(href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20Bonfire:%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/bonfires/#{dashedName}&hashtags=LearnToCode, JavaScript" target="_blank") - i.fa.fa-twitter   -arget="_blank") + a.animated.fadeIn.btn.btn-lg.btn-block.btn-twitter(target="_blank", href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20Bonfire:%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/bonfires/#{dashedName}&hashtags=LearnToCode, JavaScript") i.fa.fa-twitter   = phrase - else From 4729ef31b4d5840be15210b727ff4c4c850e3c2c Mon Sep 17 00:00:00 2001 From: terakilobyte Date: Fri, 1 May 2015 17:17:12 -0400 Subject: [PATCH 6/6] Get rid of duplicate field guide for mac keyboard shortcuts --- seed_data/field-guides.json | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/seed_data/field-guides.json b/seed_data/field-guides.json index 87af2174af8..7913443f2e8 100644 --- a/seed_data/field-guides.json +++ b/seed_data/field-guides.json @@ -235,29 +235,6 @@ "" ] }, - { - "_id": "bd7158d9c442eddfaeb5bdef", - "name": "Global Control Shortcuts for Mac", - "description": [ - "
", - "

These Global Control Shortcuts for Mac will save you hours by speeding up your typing

", - "
", - "
", - "

These global shortcuts work everywhere on a Mac:", - "
    ", - "
  • Control + F = Forward
  • ", - "
  • Control + B = Backward
  • ", - "
  • Control + N = Next Line
  • ", - "
  • Control + P = Previous Line
  • ", - "
  • Control + H = Backspace
  • ", - "
  • Control + D = Delete
  • ", - "
  • Control + A = Beginning of Line
  • ", - "
  • Control + E = End of Line
  • ", - "
  • Control + K = Kill line
  • ", - "
", - "

" - ] - }, { "_id": "bd7159d9c442eddfaeb5bdef", "name": "Global Mac Keyboard Shortcuts",