diff --git a/app.js b/app.js index a40b25f074..bd36ff727c 100755 --- a/app.js +++ b/app.js @@ -80,6 +80,20 @@ mongoose.connection.on('error', function () { app.set('port', process.env.PORT || 3000); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); + +console.log(process.env.NODE_ENV); + +if (process.env.NODE_ENV === 'production') { + app.all(/.*/, function (req, res, next) { + var host = req.header("host"); + if (host.match(/^www\..*/i)) { + next(); + } else { + res.redirect(301, "http://www." + host); + } + }); +} + app.use(compress()); var oneYear = 31557600000; app.use(express.static(__dirname + '/public', {maxAge: oneYear})); @@ -728,6 +742,7 @@ if (process.env.NODE_ENV === 'development') { /** * Start Express server. */ + app.listen(app.get('port'), function () { console.log( 'FreeCodeCamp server listening on port %d in %s mode', diff --git a/controllers/fieldGuide.js b/controllers/fieldGuide.js index 49b79e6bd6..1f19adf467 100644 --- a/controllers/fieldGuide.js +++ b/controllers/fieldGuide.js @@ -39,7 +39,11 @@ exports.showAllFieldGuides = function(req, res) { var data = {}; data.fieldGuideList = resources.allFieldGuideNames(); data.fieldGuideIds = resources.allFieldGuideIds(); - data.completedFieldGuides = req.user.completedFieldGuides; + if (req.user && req.user.completedFieldGuides) { + data.completedFieldGuides = req.user.completedFieldGuides; + } else { + data.completedFieldGuides = [] + } res.send(data); }; diff --git a/seed_data/field-guides.json b/seed_data/field-guides.json index f5f96e1c23..0d72f30919 100644 --- a/seed_data/field-guides.json +++ b/seed_data/field-guides.json @@ -5,7 +5,7 @@ "description": [ "
", "

This guide will answer many of your questions about learning to code and getting a coding job.

", - "

You can click the \"Next article\" button to go to your next article.

", + "

If you're logged in, you can click the \"Next article\" button to go to your next article.

", "

You can also click the \"Show me all articles\" button to browse all the questions we answer.

", "
" ] diff --git a/views/field-guide/show.jade b/views/field-guide/show.jade index 574abeffe8..cf78f27c39 100644 --- a/views/field-guide/show.jade +++ b/views/field-guide/show.jade @@ -15,14 +15,13 @@ block content .spacer .col-xs-12.col-sm-6.col-sm-offset-3 .text-center - .next-field-guide-button.btn.btn-primary.btn-big.btn-block Next article (ctrl + enter) - .ten-pixel-break + if user + .next-field-guide-button.btn.btn-primary.btn-big.btn-block Next article (ctrl + enter) + .ten-pixel-break #showAllButton.btn.btn-info.btn-big.btn-block Show me all articles - .spacer - .row - .col-xs-12.text-center if !user - a.btn.btn-cta.signup-btn.btn-primary(href="/login") Start learning to code (it's free) + .ten-pixel-break + a.btn.btn-big.signup-btn.btn-block(href="/login") Start learning to code (it's free) .spacer #show-all-dialog.modal(tabindex='-1') .modal-dialog.animated.fadeInUp.fast-animation