2015-03-17 21:57:05 -07:00
|
|
|
if (process.env.NODE_ENV !== 'development') {
|
|
|
|
require('newrelic');
|
|
|
|
}
|
2014-12-22 16:16:10 -08:00
|
|
|
require('dotenv').load();
|
2015-03-22 22:18:01 -07:00
|
|
|
// handle uncaught exceptions. Forever will restart process on shutdown
|
|
|
|
process.on('uncaughtException', function (err) {
|
|
|
|
console.error(
|
|
|
|
(new Date()).toUTCString() + ' uncaughtException:',
|
|
|
|
err.message
|
|
|
|
);
|
|
|
|
console.error(err.stack);
|
|
|
|
/* eslint-disable no-process-exit */
|
|
|
|
process.exit(1);
|
|
|
|
/* eslint-enable no-process-exit */
|
|
|
|
});
|
2014-01-11 22:53:31 -05:00
|
|
|
|
2014-12-23 08:48:28 -08:00
|
|
|
var express = require('express'),
|
2015-03-25 15:25:19 -07:00
|
|
|
//accepts = require('accepts'),
|
2014-12-23 08:48:28 -08:00
|
|
|
cookieParser = require('cookie-parser'),
|
|
|
|
compress = require('compression'),
|
|
|
|
session = require('express-session'),
|
|
|
|
logger = require('morgan'),
|
|
|
|
errorHandler = require('errorhandler'),
|
|
|
|
methodOverride = require('method-override'),
|
|
|
|
bodyParser = require('body-parser'),
|
|
|
|
helmet = require('helmet'),
|
|
|
|
MongoStore = require('connect-mongo')(session),
|
|
|
|
flash = require('express-flash'),
|
|
|
|
path = require('path'),
|
|
|
|
mongoose = require('mongoose'),
|
|
|
|
passport = require('passport'),
|
|
|
|
expressValidator = require('express-validator'),
|
|
|
|
connectAssets = require('connect-assets'),
|
2014-01-11 22:53:31 -05:00
|
|
|
|
2014-12-23 08:48:28 -08:00
|
|
|
/**
|
2015-01-16 18:58:27 -05:00
|
|
|
* Controllers (route handlers).
|
|
|
|
*/
|
2014-12-23 08:48:28 -08:00
|
|
|
homeController = require('./controllers/home'),
|
|
|
|
resourcesController = require('./controllers/resources'),
|
|
|
|
userController = require('./controllers/user'),
|
|
|
|
contactController = require('./controllers/contact'),
|
2015-03-24 19:08:26 -07:00
|
|
|
nonprofitController = require('./controllers/nonprofits'),
|
2015-01-11 00:45:22 -05:00
|
|
|
bonfireController = require('./controllers/bonfire'),
|
2015-02-01 23:35:27 -08:00
|
|
|
coursewareController = require('./controllers/courseware'),
|
2015-03-30 13:48:54 -07:00
|
|
|
wikiController = require('./controllers/wiki'),
|
2013-11-14 02:29:55 -05:00
|
|
|
|
2014-12-23 08:48:28 -08:00
|
|
|
/**
|
2015-03-03 19:23:56 +09:00
|
|
|
* Stories
|
2015-01-16 18:58:27 -05:00
|
|
|
*/
|
2015-03-28 23:42:07 +09:00
|
|
|
storyController = require('./controllers/story'),
|
2014-01-11 22:53:31 -05:00
|
|
|
|
2014-12-23 08:48:28 -08:00
|
|
|
/**
|
2015-01-16 18:58:27 -05:00
|
|
|
* API keys and Passport configuration.
|
|
|
|
*/
|
2014-12-23 08:48:28 -08:00
|
|
|
secrets = require('./config/secrets'),
|
|
|
|
passportConf = require('./config/passport');
|
2013-11-26 23:15:13 -05:00
|
|
|
|
2014-02-02 05:38:38 -05:00
|
|
|
/**
|
|
|
|
* Create Express server.
|
|
|
|
*/
|
|
|
|
var app = express();
|
|
|
|
|
2014-01-11 22:53:31 -05:00
|
|
|
/**
|
2014-06-06 14:58:30 -04:00
|
|
|
* Connect to MongoDB.
|
2014-01-11 22:53:31 -05:00
|
|
|
*/
|
2014-02-25 22:39:28 -05:00
|
|
|
mongoose.connect(secrets.db);
|
2015-01-16 18:58:27 -05:00
|
|
|
mongoose.connection.on('error', function () {
|
|
|
|
console.error(
|
|
|
|
'MongoDB Connection Error. Please make sure that MongoDB is running.'
|
|
|
|
);
|
2014-01-11 22:53:31 -05:00
|
|
|
});
|
2013-11-13 12:32:22 -05:00
|
|
|
|
2014-05-06 00:44:30 -04:00
|
|
|
/**
|
|
|
|
* Express configuration.
|
|
|
|
*/
|
2014-04-18 14:29:30 -04:00
|
|
|
|
2015-02-17 15:35:16 -08:00
|
|
|
|
2014-01-11 22:53:31 -05:00
|
|
|
app.set('port', process.env.PORT || 3000);
|
|
|
|
app.set('views', path.join(__dirname, 'views'));
|
|
|
|
app.set('view engine', 'jade');
|
2014-06-06 14:58:30 -04:00
|
|
|
app.use(compress());
|
2014-12-27 00:22:50 -08:00
|
|
|
var oneYear = 31557600000;
|
2015-01-16 18:58:27 -05:00
|
|
|
app.use(express.static(__dirname + '/public', {maxAge: oneYear}));
|
2014-02-21 17:29:06 -05:00
|
|
|
app.use(connectAssets({
|
2014-12-23 08:48:28 -08:00
|
|
|
paths: [
|
2015-01-16 18:58:27 -05:00
|
|
|
path.join(__dirname, 'public/css'),
|
|
|
|
path.join(__dirname, 'public/js')
|
2014-12-23 08:48:28 -08:00
|
|
|
],
|
2014-10-17 19:23:53 -07:00
|
|
|
helperContext: app.locals
|
2014-02-03 08:34:12 -05:00
|
|
|
}));
|
2014-04-12 12:43:07 -04:00
|
|
|
app.use(logger('dev'));
|
|
|
|
app.use(bodyParser.json());
|
2015-01-16 18:58:27 -05:00
|
|
|
app.use(bodyParser.urlencoded({extended: true}));
|
2014-12-23 18:20:53 -08:00
|
|
|
app.use(expressValidator({
|
|
|
|
customValidators: {
|
2015-01-16 18:58:27 -05:00
|
|
|
matchRegex: function (param, regex) {
|
2014-12-23 18:20:53 -08:00
|
|
|
return regex.test(param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
2014-04-12 12:43:07 -04:00
|
|
|
app.use(methodOverride());
|
|
|
|
app.use(cookieParser());
|
|
|
|
app.use(session({
|
2014-10-17 19:23:53 -07:00
|
|
|
resave: true,
|
|
|
|
saveUninitialized: true,
|
|
|
|
secret: secrets.sessionSecret,
|
|
|
|
store: new MongoStore({
|
|
|
|
url: secrets.db,
|
2015-03-24 21:46:42 -07:00
|
|
|
'autoReconnect': true
|
2014-10-17 19:23:53 -07:00
|
|
|
})
|
2014-01-29 00:49:09 -05:00
|
|
|
}));
|
2014-01-11 22:53:31 -05:00
|
|
|
app.use(passport.initialize());
|
|
|
|
app.use(passport.session());
|
2014-06-01 11:52:28 -04:00
|
|
|
app.use(flash());
|
2014-12-10 20:44:33 -08:00
|
|
|
app.disable('x-powered-by');
|
2014-12-23 08:48:28 -08:00
|
|
|
|
2014-12-10 20:44:33 -08:00
|
|
|
app.use(helmet.xssFilter());
|
2015-01-09 15:10:34 -08:00
|
|
|
app.use(helmet.noSniff());
|
2014-12-10 20:44:33 -08:00
|
|
|
app.use(helmet.xframe());
|
2015-02-17 15:35:16 -08:00
|
|
|
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");
|
|
|
|
next();
|
|
|
|
});
|
2014-12-23 08:48:28 -08:00
|
|
|
|
2014-12-22 12:36:45 -08:00
|
|
|
var trusted = [
|
2014-12-23 13:30:20 -08:00
|
|
|
"'self'",
|
2014-12-22 12:36:45 -08:00
|
|
|
'*.freecodecamp.com',
|
2014-12-23 08:48:28 -08:00
|
|
|
'*.gstatic.com',
|
2015-01-05 17:29:37 -08:00
|
|
|
'*.google-analytics.com',
|
|
|
|
'*.googleapis.com',
|
|
|
|
'*.google.com',
|
|
|
|
'*.gstatic.com',
|
|
|
|
'*.doubleclick.net',
|
|
|
|
'*.twitter.com',
|
2015-01-14 13:26:36 -08:00
|
|
|
'*.twitch.tv',
|
2014-12-22 12:36:45 -08:00
|
|
|
'*.twimg.com',
|
|
|
|
"'unsafe-eval'",
|
2014-12-22 15:07:32 -08:00
|
|
|
"'unsafe-inline'",
|
2015-01-05 17:29:37 -08:00
|
|
|
'*.rafflecopter.com',
|
2015-01-06 10:28:57 -05:00
|
|
|
'*.bootstrapcdn.com',
|
2015-01-05 17:29:37 -08:00
|
|
|
'*.cloudflare.com',
|
2015-03-17 16:18:41 -07:00
|
|
|
'https://*.cloudflare.com',
|
2015-01-06 10:28:57 -05:00
|
|
|
'localhost:3001',
|
2015-01-09 07:53:29 -08:00
|
|
|
'ws://localhost:3001/',
|
|
|
|
'http://localhost:3001',
|
|
|
|
'localhost:3000',
|
|
|
|
'ws://localhost:3000/',
|
2015-01-09 08:47:49 -08:00
|
|
|
'http://localhost:3000',
|
2015-01-09 15:47:52 -08:00
|
|
|
'*.ionicframework.com',
|
2015-01-11 00:07:41 -08:00
|
|
|
'https://syndication.twitter.com',
|
2015-01-22 16:52:43 -08:00
|
|
|
'*.youtube.com',
|
2015-02-21 14:22:46 -08:00
|
|
|
'*.jsdelivr.net',
|
2015-03-17 16:18:41 -07:00
|
|
|
'https://*.jsdelivr.net',
|
2015-02-21 14:22:46 -08:00
|
|
|
'*.togetherjs.com',
|
|
|
|
'https://*.togetherjs.com',
|
|
|
|
'wss://hub.togetherjs.com',
|
|
|
|
'*.ytimg.com',
|
2015-02-23 08:01:55 +09:00
|
|
|
'wss://fcctogether.herokuapp.com',
|
|
|
|
'*.bitly.com'
|
2014-12-22 12:36:45 -08:00
|
|
|
];
|
2014-12-22 13:38:48 -08:00
|
|
|
|
2014-12-10 20:44:33 -08:00
|
|
|
app.use(helmet.contentSecurityPolicy({
|
2014-12-22 12:36:45 -08:00
|
|
|
defaultSrc: trusted,
|
2015-02-19 17:18:44 -08:00
|
|
|
scriptSrc: [
|
|
|
|
'*.optimizely.com',
|
|
|
|
'*.aspnetcdn.com',
|
|
|
|
'*.d3js.org',
|
|
|
|
].concat(trusted),
|
2014-12-23 13:50:14 -08:00
|
|
|
'connect-src': [
|
2015-01-16 18:58:27 -05:00
|
|
|
'ws://*.rafflecopter.com',
|
|
|
|
'wss://*.rafflecopter.com',
|
|
|
|
'https://*.rafflecopter.com',
|
|
|
|
'ws://www.freecodecamp.com',
|
|
|
|
'http://www.freecodecamp.com'
|
2015-01-09 07:53:29 -08:00
|
|
|
].concat(trusted),
|
2014-12-22 12:36:45 -08:00
|
|
|
styleSrc: trusted,
|
2014-12-23 13:50:14 -08:00
|
|
|
imgSrc: [
|
2015-01-16 18:58:27 -05:00
|
|
|
'*.evernote.com',
|
|
|
|
'*.amazonaws.com',
|
|
|
|
'data:',
|
|
|
|
'*.licdn.com',
|
|
|
|
'*.gravatar.com',
|
|
|
|
'*.akamaihd.net',
|
|
|
|
'graph.facebook.com',
|
|
|
|
'*.githubusercontent.com',
|
|
|
|
'*.googleusercontent.com',
|
|
|
|
'*' /* allow all input since we have user submitted images for public profile*/
|
2014-12-23 13:50:14 -08:00
|
|
|
].concat(trusted),
|
|
|
|
fontSrc: ['*.googleapis.com'].concat(trusted),
|
|
|
|
mediaSrc: [
|
2015-01-16 18:58:27 -05:00
|
|
|
'*.amazonaws.com',
|
|
|
|
'*.twitter.com'
|
2015-01-09 07:53:29 -08:00
|
|
|
].concat(trusted),
|
2014-12-23 13:50:14 -08:00
|
|
|
frameSrc: [
|
2015-01-16 18:58:27 -05:00
|
|
|
'*.gitter.im',
|
2015-03-10 17:42:15 -05:00
|
|
|
'*.gitter.im https:',
|
2015-01-16 18:58:27 -05:00
|
|
|
'*.vimeo.com',
|
|
|
|
'*.twitter.com',
|
|
|
|
'*.rafflecopter.com',
|
2015-02-15 23:59:03 -08:00
|
|
|
'*.ghbtns.com'
|
2015-01-09 07:53:29 -08:00
|
|
|
].concat(trusted),
|
2014-12-10 20:44:33 -08:00
|
|
|
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
|
|
|
|
}));
|
2014-11-19 15:30:36 -08:00
|
|
|
|
2015-01-16 18:58:27 -05:00
|
|
|
app.use(function (req, res, next) {
|
2014-10-17 19:23:53 -07:00
|
|
|
// Make user object available in templates.
|
|
|
|
res.locals.user = req.user;
|
|
|
|
next();
|
2014-01-11 22:53:31 -05:00
|
|
|
});
|
2014-11-19 15:30:36 -08:00
|
|
|
|
2015-01-16 18:58:27 -05:00
|
|
|
app.use(function (req, res, next) {
|
2014-10-17 19:23:53 -07:00
|
|
|
// Remember original destination before login.
|
|
|
|
var path = req.path.split('/')[1];
|
2015-03-28 00:16:48 -05:00
|
|
|
if (/auth|login|logout|signin|signup|fonts|favicon/i.test(path)) {
|
|
|
|
return next();
|
|
|
|
} else if (/\/stories\/comments\/\w+/i.test(req.path)) {
|
2014-10-17 19:23:53 -07:00
|
|
|
return next();
|
|
|
|
}
|
|
|
|
req.session.returnTo = req.path;
|
|
|
|
next();
|
2014-03-08 14:58:27 -05:00
|
|
|
});
|
2014-11-19 15:30:36 -08:00
|
|
|
|
2014-12-23 08:48:28 -08:00
|
|
|
app.use(
|
2015-01-16 18:58:27 -05:00
|
|
|
express.static(path.join(__dirname, 'public'), {maxAge: 31557600000})
|
2014-12-23 08:48:28 -08:00
|
|
|
);
|
2014-01-08 01:37:40 -05:00
|
|
|
|
2015-03-07 02:00:21 -08:00
|
|
|
app.use(express.static(__dirname + '/public', { maxAge: 86400000 }));
|
|
|
|
|
2014-01-11 22:53:31 -05:00
|
|
|
/**
|
2014-06-06 15:23:28 -04:00
|
|
|
* Main routes.
|
2014-01-11 22:53:31 -05:00
|
|
|
*/
|
2014-11-19 15:30:36 -08:00
|
|
|
|
2015-01-14 13:28:20 -08:00
|
|
|
app.get('/', homeController.index);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
|
|
|
app.get('/privacy', function(req, res) {
|
|
|
|
res.redirect(301, "/wiki/free-code-camp's-privacy-policy");
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get('/nonprofit-project-instructions', function(req, res) {
|
|
|
|
res.redirect(301, "/wiki/free-code-camp's-privacy-policy");
|
|
|
|
});
|
|
|
|
|
2014-11-29 15:16:47 -08:00
|
|
|
app.get('/jquery-exercises', resourcesController.jqueryExercises);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-02-19 16:33:08 -08:00
|
|
|
app.get('/chat', resourcesController.chat);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
|
|
|
app.get('/live-pair-programming', function(req, res) {
|
|
|
|
res.redirect(301, '/wiki/live-stream-pair-programming-on-twitch.tv');
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get('/install-screenhero', function(req, res) {
|
|
|
|
res.redirect(301, '/wiki/install-screenhero');
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get('/guide-to-our-nonprofit-projects', function(req, res) {
|
|
|
|
res.redirect(301, '/wiki/a-guide-to-our-nonprofit-projects');
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get('/chromebook', function(req, res) {
|
|
|
|
res.redirect(301, '/wiki/chromebook');
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get('/deploy-a-website', function(req, res) {
|
|
|
|
res.redirect(301, '/wiki/deploy-a-website');
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get('/gmail-shortcuts', function(req, res) {
|
|
|
|
res.redirect(301, '/wiki/gmail-shortcuts');
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get('/nodeschool-challenges', function(req, res) {
|
|
|
|
res.redirect(301, '/wiki/nodeschool-challenges');
|
|
|
|
});
|
|
|
|
|
2015-01-26 11:38:19 -08:00
|
|
|
app.get('/stats', function(req, res) {
|
|
|
|
res.redirect(301, '/learn-to-code');
|
|
|
|
});
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-26 11:38:19 -08:00
|
|
|
app.get('/about', function(req, res) {
|
|
|
|
res.redirect(301, '/learn-to-code');
|
|
|
|
});
|
2015-03-30 15:15:07 -07:00
|
|
|
|
|
|
|
app.get('/learn-to-code', resourcesController.about);
|
|
|
|
|
|
|
|
app.get('/news', function(req, res) {
|
|
|
|
res.redirect(301, '/stories/hot');
|
|
|
|
});
|
|
|
|
|
2015-01-26 11:38:19 -08:00
|
|
|
app.get('/signin', userController.getSignin);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-26 11:38:19 -08:00
|
|
|
app.get('/login', function(req, res) {
|
|
|
|
res.redirect(301, '/signin');
|
|
|
|
});
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-26 11:38:19 -08:00
|
|
|
app.post('/signin', userController.postSignin);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-26 11:38:19 -08:00
|
|
|
app.get('/signout', userController.signout);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-26 11:38:19 -08:00
|
|
|
app.get('/logout', function(req, res) {
|
|
|
|
res.redirect(301, '/signout');
|
|
|
|
});
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2014-06-06 15:23:28 -04:00
|
|
|
app.get('/forgot', userController.getForgot);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2014-06-06 15:23:28 -04:00
|
|
|
app.post('/forgot', userController.postForgot);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2014-06-06 15:23:28 -04:00
|
|
|
app.get('/reset/:token', userController.getReset);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2014-06-06 15:23:28 -04:00
|
|
|
app.post('/reset/:token', userController.postReset);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2014-12-07 16:25:43 -08:00
|
|
|
app.get('/email-signup', userController.getEmailSignup);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2014-12-07 16:25:43 -08:00
|
|
|
app.get('/email-signin', userController.getEmailSignin);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2014-12-07 16:25:43 -08:00
|
|
|
app.post('/email-signup', userController.postEmailSignup);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-26 11:38:19 -08:00
|
|
|
app.post('/email-signin', userController.postSignin);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Nonprofit Project routes.
|
|
|
|
*/
|
|
|
|
|
2015-01-14 13:28:20 -08:00
|
|
|
app.get('/nonprofits', contactController.getNonprofitsForm);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-14 13:28:20 -08:00
|
|
|
app.post('/nonprofits', contactController.postNonprofitsForm);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-24 19:08:26 -07:00
|
|
|
app.get('/nonprofits/home', nonprofitController.nonprofitsHome);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-24 21:46:42 -07:00
|
|
|
app.get('/nonprofits/are-you-with-a-registered-nonprofit', nonprofitController.areYouWithARegisteredNonprofit);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-24 22:12:16 -07:00
|
|
|
app.get('/nonprofits/are-there-people-that-are-already-benefiting-from-your-services', nonprofitController.areTherePeopleThatAreAlreadyBenefitingFromYourServices);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-24 21:46:42 -07:00
|
|
|
app.get('/nonprofits/in-exchange-we-ask', nonprofitController.inExchangeWeAsk);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-24 21:46:42 -07:00
|
|
|
app.get('/nonprofits/ok-with-javascript', nonprofitController.okWithJavaScript);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-26 23:33:52 -07:00
|
|
|
app.get('/nonprofits/how-can-free-code-camp-help-you', nonprofitController.howCanFreeCodeCampHelpYou);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-24 21:46:42 -07:00
|
|
|
app.get('/nonprofits/what-does-your-nonprofit-do', nonprofitController.whatDoesYourNonprofitDo);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-24 21:46:42 -07:00
|
|
|
app.get('/nonprofits/link-us-to-your-website', nonprofitController.linkUsToYourWebsite);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-25 15:25:19 -07:00
|
|
|
app.get('/nonprofits/tell-us-your-name', nonprofitController.tellUsYourName);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-25 15:25:19 -07:00
|
|
|
app.get('/nonprofits/tell-us-your-email', nonprofitController.tellUsYourEmail);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-24 21:46:42 -07:00
|
|
|
app.get('/nonprofits/your-nonprofit-project-application-has-been-submitted', nonprofitController.yourNonprofitProjectApplicationHasBeenSubmitted);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-26 23:33:52 -07:00
|
|
|
app.get('/nonprofits/other-solutions', nonprofitController.otherSolutions);
|
2015-01-23 15:13:36 -08:00
|
|
|
|
2015-01-14 13:28:20 -08:00
|
|
|
app.get(
|
|
|
|
'/done-with-first-100-hours',
|
2015-01-23 15:13:36 -08:00
|
|
|
passportConf.isAuthenticated,
|
2015-01-14 13:28:20 -08:00
|
|
|
contactController.getDoneWithFirst100Hours
|
|
|
|
);
|
|
|
|
app.post(
|
|
|
|
'/done-with-first-100-hours',
|
2015-01-23 15:13:36 -08:00
|
|
|
passportConf.isAuthenticated,
|
2015-01-14 13:28:20 -08:00
|
|
|
contactController.postDoneWithFirst100Hours
|
|
|
|
);
|
2014-11-19 15:50:57 -08:00
|
|
|
app.post(
|
2015-01-16 18:58:27 -05:00
|
|
|
'/update-progress',
|
|
|
|
passportConf.isAuthenticated,
|
|
|
|
userController.updateProgress
|
2014-12-23 08:48:28 -08:00
|
|
|
);
|
2015-02-15 23:59:03 -08:00
|
|
|
|
2015-03-03 19:23:56 +09:00
|
|
|
/**
|
2015-03-30 15:15:07 -07:00
|
|
|
* Camper News routes.
|
2015-03-03 19:23:56 +09:00
|
|
|
*/
|
2015-03-06 08:11:18 +09:00
|
|
|
app.get(
|
|
|
|
'/stories/hotStories',
|
|
|
|
storyController.hotJSON
|
|
|
|
);
|
|
|
|
|
|
|
|
app.get(
|
|
|
|
'/stories/recentStories',
|
|
|
|
storyController.recentJSON
|
|
|
|
);
|
|
|
|
|
2015-03-03 19:23:56 +09:00
|
|
|
app.get(
|
|
|
|
'/stories/',
|
2015-03-06 08:11:18 +09:00
|
|
|
function(req, res) {
|
|
|
|
res.redirect(302, '/stories/hot');
|
|
|
|
}
|
2015-03-03 19:23:56 +09:00
|
|
|
);
|
2015-03-06 08:11:18 +09:00
|
|
|
|
2015-03-03 19:23:56 +09:00
|
|
|
app.get(
|
2015-03-06 08:11:18 +09:00
|
|
|
'/stories/comments/:id',
|
|
|
|
storyController.comments
|
2015-03-03 19:23:56 +09:00
|
|
|
);
|
2015-03-04 07:15:00 +09:00
|
|
|
|
2015-03-06 06:08:40 +09:00
|
|
|
app.post(
|
2015-03-07 01:57:09 +09:00
|
|
|
'/stories/comment/',
|
2015-03-06 06:08:40 +09:00
|
|
|
storyController.commentSubmit
|
|
|
|
);
|
|
|
|
|
2015-03-07 01:57:09 +09:00
|
|
|
app.post(
|
|
|
|
'/stories/comment/:id/comment',
|
|
|
|
storyController.commentOnCommentSubmit
|
|
|
|
);
|
|
|
|
|
2015-03-04 07:15:00 +09:00
|
|
|
app.get(
|
2015-03-06 08:11:18 +09:00
|
|
|
'/stories/submit',
|
|
|
|
storyController.submitNew
|
2015-03-04 07:15:00 +09:00
|
|
|
);
|
|
|
|
|
2015-03-07 17:42:22 +09:00
|
|
|
app.get(
|
2015-03-09 18:41:07 +09:00
|
|
|
'/stories/submit/new-story',
|
2015-03-07 17:42:22 +09:00
|
|
|
storyController.preSubmit
|
2015-03-05 19:21:26 +09:00
|
|
|
);
|
|
|
|
|
2015-03-07 17:42:22 +09:00
|
|
|
app.post(
|
|
|
|
'/stories/preliminary',
|
|
|
|
storyController.newStory
|
|
|
|
);
|
2015-03-06 08:11:18 +09:00
|
|
|
|
2015-03-07 18:26:49 +09:00
|
|
|
app.post(
|
|
|
|
'/stories/',
|
|
|
|
storyController.storySubmission
|
|
|
|
);
|
|
|
|
|
2015-03-06 08:11:18 +09:00
|
|
|
app.get(
|
|
|
|
'/stories/hot',
|
|
|
|
storyController.hot
|
|
|
|
);
|
|
|
|
|
|
|
|
app.get(
|
|
|
|
'/stories/recent',
|
|
|
|
storyController.recent
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
app.get(
|
|
|
|
'/stories/search',
|
|
|
|
storyController.search
|
|
|
|
);
|
|
|
|
|
2015-03-06 09:20:30 +09:00
|
|
|
app.post(
|
|
|
|
'/stories/search',
|
|
|
|
storyController.getStories
|
|
|
|
);
|
|
|
|
|
2015-03-03 19:50:16 +09:00
|
|
|
app.get(
|
|
|
|
'/stories/:storyName',
|
|
|
|
storyController.returnIndividualStory
|
|
|
|
);
|
2015-03-06 08:11:18 +09:00
|
|
|
|
2015-03-03 22:03:33 +09:00
|
|
|
app.post(
|
2015-03-04 07:15:00 +09:00
|
|
|
'/stories/upvote/',
|
2015-03-03 22:03:33 +09:00
|
|
|
storyController.upvote
|
|
|
|
);
|
2015-03-03 19:23:56 +09:00
|
|
|
|
2014-11-19 15:30:36 -08:00
|
|
|
app.all('/account', passportConf.isAuthenticated);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-06 00:52:30 -05:00
|
|
|
app.get('/account/api', userController.getAccountAngular);
|
2015-01-27 20:12:51 -05:00
|
|
|
|
2015-02-16 23:35:02 -08:00
|
|
|
/**
|
|
|
|
* API routes
|
|
|
|
*/
|
|
|
|
|
|
|
|
app.get('/api/github', resourcesController.githubCalls);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-27 23:30:06 -07:00
|
|
|
app.get('/api/blogger', resourcesController.bloggerCalls);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-27 23:30:06 -07:00
|
|
|
app.get('/api/trello', resourcesController.trelloCalls);
|
2015-02-16 23:35:02 -08:00
|
|
|
|
2015-01-27 20:12:51 -05:00
|
|
|
/**
|
|
|
|
* Bonfire related routes
|
|
|
|
*/
|
2015-02-22 17:36:43 +09:00
|
|
|
|
2015-02-22 16:27:38 +09:00
|
|
|
app.get('/bonfires/getBonfireList', bonfireController.showAllBonfires);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-30 15:55:00 -07:00
|
|
|
app.get('/wiki/getWikiList', wikiController.showAllWikis);
|
|
|
|
|
2015-01-24 14:42:34 -08:00
|
|
|
app.get('/playground', bonfireController.index);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-27 20:12:51 -05:00
|
|
|
app.get('/bonfires', bonfireController.returnNextBonfire);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-27 20:12:51 -05:00
|
|
|
app.get('/bonfire-json-generator', bonfireController.returnGenerator);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-27 20:12:51 -05:00
|
|
|
app.post('/bonfire-json-generator', bonfireController.generateChallenge);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-27 20:12:51 -05:00
|
|
|
app.get('/bonfire-challenge-generator', bonfireController.publicGenerator);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-30 15:55:00 -07:00
|
|
|
app.post('/bonfire-challenge-generator', bonfireController.testBonfire);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-22 13:20:46 -05:00
|
|
|
app.get(
|
2015-01-26 18:28:14 -05:00
|
|
|
'/bonfires/:bonfireName',
|
2015-01-24 14:29:50 -08:00
|
|
|
bonfireController.returnIndividualBonfire
|
2015-01-22 13:20:46 -05:00
|
|
|
);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-26 12:30:04 -05:00
|
|
|
app.get('/bonfire', function(req, res) {
|
|
|
|
res.redirect(301, '/playground');
|
|
|
|
});
|
2014-02-01 03:30:14 -05:00
|
|
|
|
2015-03-30 13:48:54 -07:00
|
|
|
/**
|
|
|
|
* Wiki related routes
|
|
|
|
*/
|
2015-02-22 16:27:38 +09:00
|
|
|
|
2015-03-30 13:48:54 -07:00
|
|
|
app.get(
|
|
|
|
'/wiki/:wikiName',
|
|
|
|
wikiController.returnIndividualWiki
|
|
|
|
);
|
|
|
|
|
|
|
|
app.get(
|
|
|
|
'/wiki',
|
|
|
|
wikiController.showAllWikis
|
|
|
|
);
|
2015-02-22 16:27:38 +09:00
|
|
|
|
2015-02-01 22:39:59 -08:00
|
|
|
app.post('/completed-bonfire/', bonfireController.completedBonfire);
|
2015-01-24 00:44:08 -05:00
|
|
|
|
2015-02-01 23:35:27 -08:00
|
|
|
/**
|
|
|
|
* Courseware related routes
|
|
|
|
*/
|
|
|
|
|
2015-03-21 18:42:19 +09:00
|
|
|
app.get('/challenges/', coursewareController.returnNextCourseware);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-21 18:42:19 +09:00
|
|
|
app.get('/challenges/getCoursewareList', coursewareController.showAllCoursewares);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-02-01 23:35:27 -08:00
|
|
|
app.get(
|
2015-03-21 18:42:19 +09:00
|
|
|
'/challenges/:coursewareName',
|
2015-02-01 23:35:27 -08:00
|
|
|
coursewareController.returnIndividualCourseware
|
|
|
|
);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-02-01 23:35:27 -08:00
|
|
|
app.post('/completed-courseware/', coursewareController.completedCourseware);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-29 20:39:41 +09:00
|
|
|
app.post('/completed-zipline-or-basejump',
|
|
|
|
coursewareController.completedZiplineOrBasejump);
|
2015-02-01 23:35:27 -08:00
|
|
|
|
2015-01-27 20:12:51 -05:00
|
|
|
// Unique Check API route
|
|
|
|
app.get('/api/checkUniqueUsername/:username', userController.checkUniqueUsername);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-27 20:12:51 -05:00
|
|
|
app.get('/api/checkExistingUsername/:username', userController.checkExistingUsername);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-27 20:12:51 -05:00
|
|
|
app.get('/api/checkUniqueEmail/:email', userController.checkUniqueEmail);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-27 20:12:51 -05:00
|
|
|
app.get('/account', userController.getAccount);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-27 20:12:51 -05:00
|
|
|
app.post('/account/profile', userController.postUpdateProfile);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-27 20:12:51 -05:00
|
|
|
app.post('/account/password', userController.postUpdatePassword);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-27 20:12:51 -05:00
|
|
|
app.post('/account/delete', userController.postDeleteAccount);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-01-27 20:12:51 -05:00
|
|
|
app.get('/account/unlink/:provider', userController.getOauthUnlink);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2015-03-06 00:20:39 -08:00
|
|
|
app.get('/sitemap.xml', resourcesController.sitemap);
|
2014-02-01 03:30:14 -05:00
|
|
|
/**
|
2014-06-06 14:58:30 -04:00
|
|
|
* OAuth sign-in routes.
|
2014-02-01 03:30:14 -05:00
|
|
|
*/
|
2014-12-23 13:50:14 -08:00
|
|
|
|
|
|
|
var passportOptions = {
|
2015-01-16 18:58:27 -05:00
|
|
|
successRedirect: '/',
|
|
|
|
failureRedirect: '/login'
|
2014-12-23 13:50:14 -08:00
|
|
|
};
|
|
|
|
|
2015-01-17 18:52:58 -08:00
|
|
|
app.get('/auth/twitter', passport.authenticate('twitter'));
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2014-11-19 15:30:36 -08:00
|
|
|
app.get(
|
2015-01-16 18:58:27 -05:00
|
|
|
'/auth/twitter/callback',
|
|
|
|
passport.authenticate('twitter', {
|
|
|
|
successRedirect: '/',
|
|
|
|
failureRedirect: '/login'
|
|
|
|
})
|
2014-12-23 13:50:14 -08:00
|
|
|
);
|
|
|
|
|
2014-11-19 15:30:36 -08:00
|
|
|
app.get(
|
2015-01-16 18:58:27 -05:00
|
|
|
'/auth/linkedin',
|
|
|
|
passport.authenticate('linkedin', {
|
|
|
|
state: 'SOME STATE'
|
|
|
|
})
|
2014-12-23 13:50:14 -08:00
|
|
|
);
|
2014-11-19 15:30:36 -08:00
|
|
|
|
|
|
|
app.get(
|
2015-01-16 18:58:27 -05:00
|
|
|
'/auth/linkedin/callback',
|
|
|
|
passport.authenticate('linkedin', passportOptions)
|
2014-12-23 13:50:14 -08:00
|
|
|
);
|
2014-11-19 15:30:36 -08:00
|
|
|
|
2014-12-23 08:48:28 -08:00
|
|
|
app.get(
|
2015-01-16 18:58:27 -05:00
|
|
|
'/auth/facebook',
|
|
|
|
passport.authenticate('facebook', {scope: ['email', 'user_location']})
|
2014-12-23 08:48:28 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
app.get(
|
2015-01-16 18:58:27 -05:00
|
|
|
'/auth/facebook/callback',
|
|
|
|
passport.authenticate('facebook', passportOptions), function (req, res) {
|
|
|
|
res.redirect(req.session.returnTo || '/');
|
|
|
|
}
|
2014-12-23 08:48:28 -08:00
|
|
|
);
|
2014-11-29 22:22:27 -08:00
|
|
|
|
|
|
|
app.get('/auth/github', passport.authenticate('github'));
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2014-12-23 08:48:28 -08:00
|
|
|
app.get(
|
2015-01-16 18:58:27 -05:00
|
|
|
'/auth/github/callback',
|
|
|
|
passport.authenticate('github', passportOptions), function (req, res) {
|
|
|
|
res.redirect(req.session.returnTo || '/');
|
|
|
|
}
|
2014-12-23 08:48:28 -08:00
|
|
|
);
|
2014-11-29 22:22:27 -08:00
|
|
|
|
2014-12-23 08:48:28 -08:00
|
|
|
app.get(
|
2015-01-16 18:58:27 -05:00
|
|
|
'/auth/google',
|
|
|
|
passport.authenticate('google', {scope: 'profile email'})
|
2014-12-23 08:48:28 -08:00
|
|
|
);
|
2015-03-30 15:15:07 -07:00
|
|
|
|
2014-12-23 08:48:28 -08:00
|
|
|
app.get(
|
2015-01-16 18:58:27 -05:00
|
|
|
'/auth/google/callback',
|
|
|
|
passport.authenticate('google', passportOptions), function (req, res) {
|
|
|
|
res.redirect(req.session.returnTo || '/');
|
|
|
|
}
|
2014-12-23 08:48:28 -08:00
|
|
|
);
|
2014-11-29 22:22:27 -08:00
|
|
|
|
2015-03-24 08:03:59 -07:00
|
|
|
// put this route last
|
2015-01-17 18:52:58 -08:00
|
|
|
app.get(
|
|
|
|
'/:username',
|
|
|
|
userController.returnUser
|
|
|
|
);
|
2015-01-11 00:45:22 -05:00
|
|
|
|
2014-11-19 15:30:36 -08:00
|
|
|
/**
|
|
|
|
* 500 Error Handler.
|
|
|
|
*/
|
2015-03-24 08:03:59 -07:00
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
app.use(errorHandler({ log: true }));
|
|
|
|
} else {
|
|
|
|
// error handling in production
|
|
|
|
app.use(function(err, req, res, next) {
|
|
|
|
|
|
|
|
// respect err.status
|
|
|
|
if (err.status) {
|
|
|
|
res.statusCode = err.status;
|
|
|
|
}
|
|
|
|
|
|
|
|
// default status code to 500
|
|
|
|
if (res.statusCode < 400) {
|
|
|
|
res.statusCode = 500;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse res type
|
|
|
|
var accept = accepts(req);
|
|
|
|
var type = accept.type('html', 'json', 'text');
|
|
|
|
|
|
|
|
var message = 'opps! Something went wrong. Please try again later';
|
|
|
|
if (type === 'html') {
|
|
|
|
req.flash('errors', { msg: message });
|
|
|
|
return res.redirect('/');
|
|
|
|
// json
|
|
|
|
} else if (type === 'json') {
|
|
|
|
res.setHeader('Content-Type', 'application/json');
|
|
|
|
return res.send({ message: message });
|
|
|
|
// plain text
|
|
|
|
} else {
|
|
|
|
res.setHeader('Content-Type', 'text/plain');
|
|
|
|
return res.send(message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-11-19 15:30:36 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Start Express server.
|
|
|
|
*/
|
2015-01-16 18:58:27 -05:00
|
|
|
app.listen(app.get('port'), function () {
|
|
|
|
console.log(
|
|
|
|
'FreeCodeCamp server listening on port %d in %s mode',
|
|
|
|
app.get('port'),
|
|
|
|
app.get('env')
|
|
|
|
);
|
2014-11-19 15:30:36 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = app;
|