Skip to content

Commit

Permalink
fix FCC running using router syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkeley Martinez authored and Berkeley Martinez committed Jun 2, 2015
1 parent 7bb11e9 commit 7643f1c
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 77 deletions.
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var gulp = require('gulp'),
eslint = require('gulp-eslint');

var paths = {
server: './server.js',
server: './server/server.js',
serverIgnore: []
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"npm": "2.3.0"
},
"scripts": {
"start": "node app.js",
"start": "node server/server.js",
"lint": "eslint --ext=.js,.jsx .",
"test": "mocha"
},
Expand Down
68 changes: 68 additions & 0 deletions server/boot/passport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
var express = require('express'),
passport = require('passport'),
passportConf = require('../../config/passport');

var router = express.Router();
var passportOptions = {
successRedirect: '/',
failureRedirect: '/login'
};

router.all('/account', passportConf.isAuthenticated);

router.get('/auth/twitter', passport.authenticate('twitter'));

router.get(
'/auth/twitter/callback',
passport.authenticate('twitter', {
successRedirect: '/',
failureRedirect: '/login'
})
);

router.get(
'/auth/linkedin',
passport.authenticate('linkedin', {
state: 'SOME STATE'
})
);

router.get(
'/auth/linkedin/callback',
passport.authenticate('linkedin', passportOptions)
);

router.get(
'/auth/facebook',
passport.authenticate('facebook', {scope: ['email', 'user_location']})
);

router.get(
'/auth/facebook/callback',
passport.authenticate('facebook', passportOptions), function (req, res) {
res.redirect(req.session.returnTo || '/');
}
);

router.get('/auth/github', passport.authenticate('github'));

router.get(
'/auth/github/callback',
passport.authenticate('github', passportOptions), function (req, res) {
res.redirect(req.session.returnTo || '/');
}
);

router.get(
'/auth/google',
passport.authenticate('google', {scope: 'profile email'})
);

router.get(
'/auth/google/callback',
passport.authenticate('google', passportOptions), function (req, res) {
res.redirect(req.session.returnTo || '/');
}
);

module.exports = router;
10 changes: 6 additions & 4 deletions server/boot/user.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
var _ = require('lodash'),
R = require('ramda'),
async = require('async'),
crypto = require('crypto'),
nodemailer = require('nodemailer'),
passport = require('passport'),
User = require('../../models/User'),
secrets = require('../../config/secrets'),
moment = require('moment'),
express = require('express'),
debug = require('debug')('freecc:cntr:userController'),
resources = require('./../resources/resources'),
R = require('ramda');

User = require('../../models/User'),
secrets = require('../../config/secrets'),
resources = require('./../resources/resources');

var router = express.Router();
router.get('/login', function(req, res) {
res.redirect(301, '/signin');
});
Expand Down
2 changes: 1 addition & 1 deletion server/boot/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var express = require('express'),
Slack = require('node-slack'),
request = require('request'),
debug = require('debug')('freecc:cntr:resources'),
constantStrings = require('./constantStrings.json'),
constantStrings = require('../resources/constantStrings.json'),

User = require('../../models/User'),
Challenge = require('./../../models/Challenge'),
Expand Down
4 changes: 2 additions & 2 deletions server/resources/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ Array.zip = function(left, right, combinerFunction) {
if (!challengeMap) {
var localChallengeMap = {};
var files = fs.readdirSync(
path.join(__dirname, '/../seed_data/challenges')
path.join(__dirname, '../../seed_data/challenges')
);
var keyCounter = 0;
files = files.map(function (file) {
return require(
path.join(__dirname, '/../seed_data/challenges/' + file)
path.join(__dirname, '../../seed_data/challenges/' + file)
);
});
files = files.sort(function (a, b) {
Expand Down
72 changes: 4 additions & 68 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var express = require('express'),
* routers.
*/
homeRouter = require('./boot/home'),
resourcesRouter = require('./resources/resources'),
userRouter = require('./boot/user'),
fieldGuideRouter = require('./boot/fieldGuide'),
challengeMapRouter = require('./boot/challengeMap'),
Expand All @@ -42,12 +41,12 @@ var express = require('express'),
redirectsRouter = require('./boot/redirects'),
utilityRouter = require('./boot/utility'),
storyRouter = require('./boot/story'),
passportRouter = require('./boot/passport'),

/**
* API keys and Passport configuration.
*/
secrets = require('./../config/secrets'),
passportConf = require('./../config/passport');
secrets = require('./../config/secrets');

/**
* Create Express server.
Expand Down Expand Up @@ -199,7 +198,7 @@ app.use(function (req, res, next) {
});

app.use(
express.static(path.join(__dirname, '/public'), { maxAge: 86400000 })
express.static(path.join(__dirname, '../public'), { maxAge: 86400000 })
);

app.use(function (req, res, next) {
Expand All @@ -216,7 +215,6 @@ app.use(function (req, res, next) {

// add sub routers
app.use(homeRouter);
app.use(resourcesRouter);
app.use(userRouter);
app.use(fieldGuideRouter);
app.use(challengeMapRouter);
Expand All @@ -225,74 +223,12 @@ app.use(jobsRouter);
app.use(redirectsRouter);
app.use(utilityRouter);
app.use(storyRouter);

app.use(passportRouter);

/**
* OAuth sign-in routes.
*/

app.all('/account', passportConf.isAuthenticated);
var passportOptions = {
successRedirect: '/',
failureRedirect: '/login'
};

app.get('/auth/twitter', passport.authenticate('twitter'));

app.get(
'/auth/twitter/callback',
passport.authenticate('twitter', {
successRedirect: '/',
failureRedirect: '/login'
})
);

app.get(
'/auth/linkedin',
passport.authenticate('linkedin', {
state: 'SOME STATE'
})
);

app.get(
'/auth/linkedin/callback',
passport.authenticate('linkedin', passportOptions)
);

app.get(
'/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 || '/');
}
);

app.get('/auth/github', passport.authenticate('github'));

app.get(
'/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'})
);

app.get(
'/auth/google/callback',
passport.authenticate('google', passportOptions), function (req, res) {
res.redirect(req.session.returnTo || '/');
}
);


/**
* 500 Error Handler.
*/
Expand Down

0 comments on commit 7643f1c

Please sign in to comment.