Skip to content

Commit

Permalink
Merge pull request #81 from FullstackAcademy/next-everything
Browse files Browse the repository at this point in the history
Next everything
  • Loading branch information
joedotjs authored Sep 18, 2016
2 parents d574821 + a109c30 commit 05f2811
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
7 changes: 5 additions & 2 deletions generated/server/app/configure/authentication/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ module.exports = function (app, db) {
// We provide a simple GET /session in order to get session information directly.
// This is used by the browser application (Angular) to determine if a user is
// logged in already.
app.get('/session', function (req, res) {
app.get('/session', function (req, res, next) {
var err;
if (req.user) {
res.send({ user: req.user.sanitize() });
} else {
res.status(401).send('No authenticated user.');
err = new Error('No authenticated user.');
err.status = 401;
next(err);
}
});

Expand Down
8 changes: 6 additions & 2 deletions generated/server/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ module.exports = function (db) {
*/
app.use(function (req, res, next) {

var err;

if (path.extname(req.path).length > 0) {
res.status(404).end();
err = new Error('Not found.');
err.status = 404;
next(err);
} else {
next(null);
next();
}

});
Expand Down
6 changes: 4 additions & 2 deletions generated/server/app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ router.use('/members', require('./members'));

// Make sure this is after all of
// the registered routes!
router.use(function (req, res) {
res.status(404).end();
router.use(function (req, res, next) {
var err = new Error('Not found.');
err.status = 404;
next(err);
});
5 changes: 4 additions & 1 deletion generated/server/app/routes/members/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ module.exports = router;
var _ = require('lodash');

var ensureAuthenticated = function (req, res, next) {
var err;
if (req.isAuthenticated()) {
next();
} else {
res.status(401).end();
err = new Error('You must be logged in.');
err.status = 401;
next(err);
}
};

Expand Down

0 comments on commit 05f2811

Please sign in to comment.