Add ability to filter beta challenges from production

This PR adds the ability to test out challenges in beta
without fear that they will leak to production servers.

In development all challenges will display.

In production all challenges marked 'isBeta' will be filtered out
except in the case the environmental variable `BETA` is set ture,
in which case all challenges will display.
This commit is contained in:
Berkeley Martinez
2015-10-06 22:37:08 -07:00
parent 914f2ef0b8
commit 44fd85dff8
3 changed files with 14 additions and 1 deletions

View File

@ -43,6 +43,7 @@ Challenge.destroyAll(function(err, info) {
var challengeSpec = require('./challenges/' + file); var challengeSpec = require('./challenges/' + file);
var order = challengeSpec.order; var order = challengeSpec.order;
var block = challengeSpec.name; var block = challengeSpec.name;
var isBeta = !!challengeSpec.isBeta;
// challenge file has no challenges... // challenge file has no challenges...
if (challengeSpec.challenges.length === 0) { if (challengeSpec.challenges.length === 0) {
@ -66,6 +67,7 @@ Challenge.destroyAll(function(err, info) {
challenge.order = order; challenge.order = order;
challenge.suborder = index + 1; challenge.suborder = index + 1;
challenge.block = block; challenge.block = block;
challenge.isBeta = challenge.isBeta || isBeta;
return challenge; return challenge;
}); });

View File

@ -16,6 +16,8 @@ import {
ifNoUserSend ifNoUserSend
} from '../utils/middleware'; } from '../utils/middleware';
const isDev = process.env.NODE_ENV !== 'production';
const isBeta = !!process.env.BETA;
const debug = debugFactory('freecc:challenges'); const debug = debugFactory('freecc:challenges');
const challengesRegex = /^(bonfire|waypoint|zipline|basejump)/i; const challengesRegex = /^(bonfire|waypoint|zipline|basejump)/i;
const firstChallenge = 'waypoint-say-hello-to-html-elements'; const firstChallenge = 'waypoint-say-hello-to-html-elements';
@ -105,6 +107,9 @@ module.exports = function(app) {
null, null,
Scheduler.default Scheduler.default
)) ))
// filter out all challenges that have isBeta flag set
// except in development or beta site
.filter(challenge => isDev || isBeta || !challenge.isBeta)
.shareReplay(); .shareReplay();
// create a stream of challenge blocks // create a stream of challenge blocks
@ -543,8 +548,10 @@ module.exports = function(app) {
} }
return sum; return sum;
}, 0); }, 0);
const isBeta = _.every(blockArray, 'isBeta');
return { return {
isBeta,
name: blockArray[0].block, name: blockArray[0].block,
dashedName: dasherize(blockArray[0].block), dashedName: dasherize(blockArray[0].block),
challenges: blockArray, challenges: blockArray,

View File

@ -16,6 +16,7 @@ var getUsernameFromProvider = require('./utils/auth').getUsernameFromProvider;
var generateKey = var generateKey =
require('loopback-component-passport/lib/models/utils').generateKey; require('loopback-component-passport/lib/models/utils').generateKey;
var isBeta = !!process.env.BETA;
var app = loopback(); var app = loopback();
expressState.extend(app); expressState.extend(app);
@ -96,10 +97,13 @@ app.start = function() {
app.listen(app.get('port'), function() { app.listen(app.get('port'), function() {
app.emit('started'); app.emit('started');
console.log( console.log(
'FreeCodeCamp server listening on port %d in %s mode', 'FreeCodeCamp server listening on port %d in %s',
app.get('port'), app.get('port'),
app.get('env') app.get('env')
); );
if (isBeta) {
console.log('Free Code Camp is in beta mode');
}
}); });
}; };