Skip to content

Commit

Permalink
resolve merge conflict in app.js while merging in master, get rid of …
Browse files Browse the repository at this point in the history
…completed-challenge route
  • Loading branch information
terakilobyte committed Mar 25, 2015
2 parents e9c6498 + 8a357dd commit 25ae3ec
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 97 deletions.
59 changes: 52 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ if (process.env.NODE_ENV !== 'development') {
require('newrelic');
}
require('dotenv').load();
/**
* Module dependencies.
*/
// 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 */
});

var express = require('express'),
accepts = require('accepts'),
cookieParser = require('cookie-parser'),
compress = require('compression'),
session = require('express-session'),
Expand Down Expand Up @@ -430,7 +439,6 @@ app.get('/account/unlink/:provider', userController.getOauthUnlink);
app.get('/sitemap.xml', resourcesController.sitemap);



/**
* OAuth sign-in routes.
*/
Expand Down Expand Up @@ -492,17 +500,54 @@ app.get(
}
);

//put this route last
app.get('/induce-vomiting', function(req, res, next) {
next(new Error('vomiting induced'));
});

// put this route last
app.get(
'/:username',
userController.returnUser
);


/**
* 500 Error Handler.
*/
app.use(errorHandler());
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);
}
});
}

/**
* Start Express server.
Expand Down
Loading

0 comments on commit 25ae3ec

Please sign in to comment.