From 4f90ef2945bbd14022133a4f44cde4771980ee7f Mon Sep 17 00:00:00 2001 From: Mark Nyon Date: Sun, 1 Nov 2015 15:16:44 -0500 Subject: [PATCH] Added rollbar to app.js and #16 Initial addition of [Rollbar](https://rollbar.com) to the application. This baseline implementation adds a message upon server startup as well as handling any uncaught exceptions. - app.js - Added Rollbar with server side code from service. Added uncaught exception handler to log unexpected errors. Added code to link to Rollbar middleware. --- app.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app.js b/app.js index d0254f769..99a399bc4 100644 --- a/app.js +++ b/app.js @@ -12,11 +12,18 @@ var config = require('./config'), passport = require('passport'), models = require('./models/index'), helmet = require('helmet'), + rollbar = require("rollbar"), csrf = require('csurf'); //create express app var app = express(); +// Rollbar initialization +rollbar.init("ba471954344648d490ea209ff586ae43"); + +// record a generic message and send to rollbar +rollbar.reportMessage("Rollbar started: " + Date.now()); + //keep reference to config app.config = config; @@ -35,6 +42,19 @@ app.set('view engine', 'jade'); app.use(require('morgan')('dev')); app.use(require('compression')()); app.use(require('serve-static')(path.join(__dirname, 'public'))); + +// Use the rollbar error handler to send exceptions to your rollbar account +app.use(rollbar.errorHandler('ba471954344648d490ea209ff586ae43')); + +var options = { + // Call process.exit(1) when an uncaught exception occurs but after reporting all + // pending errors to Rollbar. + // + // Default: false + exitOnUncaughtException: true +}; +rollbar.handleUncaughtExceptions("ba471954344648d490ea209ff586ae43", options); + app.use(require('method-override')()); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true }));