How to use the raven.requestHandler function in raven

To help you get started, we’ve selected a few raven examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github devfsa / overflow-news / src / server.js View on Github external
const Feed = require('./models/feed');

const app = express();
const { PORT = 8080 } = process.env;

// Start raven to catch exceptions
Raven.config(process.env.SENTRY_DSN).install();
mongoose.connect(process.env.MONGO_URI);
app.locals.moment = moment;

app.set('views', path.join(__dirname, './views'));
app.set('view engine', 'ejs');
app.set('cache', false);

// The request handler must be the first middleware on the app
app.use(Raven.requestHandler());
app.use(cors());
// app.use(graphqlRouter);

app.get('/feeds', async (req, res) => {
  const feeds = await Feed.find({})
    .limit(50)
    .sort({ 'date': -1 });
  res.render('feeds', { feeds });
});

const listPosts = async (req, res) => {
  const perPage = 30;
  const { page = 1 } = req.params;
  const offset = (perPage * page) - perPage;

  const [ posts, count] = await Promise.all([
github openspending / os-packager / app / index.js View on Github external
app.set('trust proxy', true);

    app.set('config', config);
    var usePort = config.get('app:port');
    if (port) {
      usePort = port;
    }
    app.set('port', usePort);
    app.set('views', path.join(__dirname, '/views'));

    // Sentry monitoring
    var sentryDSN = config.get('sentryDSN');
    if (sentryDSN != null) {
      Raven.config(sentryDSN).install();
      app.use(Raven.requestHandler());
      app.use(Raven.errorHandler());

      // Fallthrough error handler
      app.use(function onError(err, req, res, next) {
        // The error id is attached to `res.sentry` to be returned
        // and optionally displayed to the user for support.
        res.statusCode = 500;
        res.end('An error occurred: ' + res.sentry + '\n');
      });
    } else {
      console.log('Sentry DSN not configured');
    }

    // Middlewares
    if (config.get('env') == 'test') {
      app.use(express.static(path.join(__dirname, '/../tests/data')));
github mjackson / unpkg / modules / createServer.js View on Github external
function createServer(publicDir, statsFile) {
  const app = express();

  app.disable('x-powered-by');

  if (process.env.SENTRY_DSN) {
    app.use(raven.requestHandler());
  }

  if (process.env.NODE_ENV !== 'test') {
    app.use(
      morgan(
        // Modified version of Heroku's log format
        // https://devcenter.heroku.com/articles/http-routing#heroku-router-log-format
        'method=:method path=":url" host=:req[host] request_id=:req[x-request-id] cf_ray=:req[cf-ray] fwd=:fwd status=:status bytes=:res[content-length]'
      )
    );
  }

  // app.use(errorHandler);

  if (publicDir) {
    app.use(express.static(publicDir, { maxAge: '365d' }));
github integrations / slack / lib / error-handler.js View on Github external
setup: (app) => {
    Raven.disableConsoleAlerts();
    Raven.config(process.env.SENTRY_DSN, {
      release: process.env.HEROKU_SLUG_COMMIT,
    }).install();

    app.use(Raven.requestHandler());

    const timeoutValue = '10s';
    app.use(timeout(timeoutValue));
    app.use((req, res, next) => {
      req.on('timeout', () => {
        const errorInfo = {
          ...defaultErrorInfo,
          isTimeout: true,
        };
        req.log.warn(errorInfo, `Request timed out after ${timeoutValue}.`);
      });

      next();
    });

    // Route for testing error handling
github TeamHive / nestjs-seed / src / main.ts View on Github external
async function bootstrap() {
    const consoleLogger = log4js.getLogger();

    try {
        const app = await NestFactory.create(ApplicationModule);

        // Raven
        if (process.env.DEPLOYMENT) {
            Raven.config(config.get('raven.dsn'), {
                release: process.env.npm_package_version,
                environment: config.util.getEnv('NODE_ENV')
            }).install();

            app.use(Raven['requestHandler']());
        }

        // Handle uncaught exceptions
        const coreModule = app.select(CoreModule);
        const errorHandler = coreModule.get(ErrorHandler);

        NodeEventHandler.handleUnhandledRejection(errorHandler);
        NodeEventHandler.handleUncaughtException(errorHandler);

        // Error handlers
        const commonModule = app.select(CommonModule);
        app.useGlobalFilters(
            commonModule.get(UncaughtExceptionFilter),
            commonModule.get(PassiveHttpExceptionFilter),
            commonModule.get(RedirectHttpExceptionFilter),
            commonModule.get(LoggedHttpExceptionFilter)
github fruum / fruum / server / main.js View on Github external
var loader_root = path.resolve(__dirname + '/../loader');
  var fruum_root = path.resolve(__dirname + '/..');

  // create logs folder
  if (!fs.existsSync(options.logs)) {
    logger.system('Creating logs folder: ' + options.logs);
    fs.mkdirSync(options.logs);
  }

  // suppress plugins on CLI
  if (cli_cmd) delete options.plugins;

  // ------------------------------ SERVER SETUP -------------------------------

  if (options.sentry && options.sentry.dsn) {
    app.use(Raven.requestHandler());
  }

  // enable CORS
  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();
  });

  // enable compression on express
  app.use(compress());

  // enable body parse (required for POST)
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(bodyParser.json());
github zestedesavoir / zds-site / zmarkdown / markdown-server.js View on Github external
function serverStart () {
  const {
    toHTML,
    toLatex,
    toLatexDocument,
  } = require('./markdown-handlers')(Raven)

  const app = express()

  app.use(Raven.requestHandler())
  app.use(Raven.errorHandler())

  app.use(bodyParser.json({limit: '5mb'}))
  app.post('/latex', controllerFactory(toLatex))
  app.post('/latex-document', controllerFactory(toLatexDocument))
  app.post('/html', controllerFactory(toHTML))

  const server = app.listen(27272, () => {
    const host = server.address().address
    const port = server.address().port

    console.warn('zmarkdown server listening at http://%s:%s', host, port)
  })
}
github mozilla-services / screenshots / server / src / ravenclient.js View on Github external
exports.addRavenRequestHandler = function(app) {
  if (useRaven) {
    app.use(Raven.requestHandler());
  }
};
github zestedesavoir / zmarkdown / packages / zmarkdown / server / app.js View on Github external
release: process.env.SENTRY_RELEASE || zmdVersion,
  environment: process.env.SENTRY_ENVIRONMENT || process.env.ZDS_ENVIRONMENT,
}).install()

const {
  toEPUB,
  toHTML,
  toLatex,
  toLatexDocument,
} = require('./handlers')(Raven)

const app = express()

app.use(cors())

app.use(Raven.requestHandler())
app.use(Raven.errorHandler())

app.use('/static', express.static(path.join(__dirname, 'static')))

app.post('/epub', bodyParser.json({limit: '5mb'}), controllerFactory(toEPUB))
app.post('/html', bodyParser.json({limit: '300kb'}), controllerFactory(toHTML))
app.post('/latex', bodyParser.json({limit: '5mb'}), controllerFactory(toLatex))
app.post('/latex-document', bodyParser.json({limit: '5mb'}), controllerFactory(toLatexDocument))

const munin = require('./munin')
app.get('/munin/config/:plugin', munin('config'))
app.get('/munin/:plugin', munin())

app.get('/', (req, res) => {
  res.send('zmd is running\n')
})