0.1.2 • Published 7 years ago

shazam-middleware v0.1.2

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

shazam-middleware

NPM Version NPM Downloads GitHub issues GitHub forks Twitter

What is shazam?

  • Shazam it's a express middleware.

What he does?

  • HTTP request logger like morgan (Method, Status Code, Browser, IP)
  • Notify on slack channel when errors occurs.

Requirements

Installation

npm install --save shazam-middleware

or

yarn add shazam-middleware

Slack

Paramters Configuration

 slack: {
        urlHook: '' // Url Hook of your slack,
        channel: '' // Name of your channel (Without '#'),
        iconUrl: '' // Customize the icon of bot (default: "http://dclegends.wiki/images/d/d9/Shazam_Billy_Batson_Portrait.png"),
        botusername: '' // Customize the name of bot (default: Shazam)
    },
    api: {
        name: '' // Name of your api,
        version: '' // Version of your api
    }

Code example to do the Magic! (Automatic)

const app = require('express')();

// Don't forget to configure the paramters
const shazam = require('shazam-middleware')({
    slack: {
        urlHook: process.env.urlHook,
        channel: process.env.channel,
        iconUrl: process.env.iconUrl,
        botusername: process.env.botusername
    },
    api: {
        name: 'My App',
        version: 1
    }
});

// Activate validation on process `uncaughtException` and `unhandledRejection`
shazam.handler;

// Now, we wanna log all requests
app.use(shazam.log);

// Look Here, one route with error
app.get("/error", (req, res, next) => {
    batata
    res.status(200).send({ retorno: 'ok' })
})

// Now, we will look for all exceptions from ours routes
app.use(shazam.exception);

// Start the Server
app.listen(4600, () => {
    console.log('APP WORKS http://localhost:4600')
})

// Fine! It`s All!

If you return a object like this patern, and use next(), you can trigger the message on Slack Channel.

  app.get("/error/next", (req, res, next) => {
        next({
            message: {
                userMessage: 'Hey, user! Don´t Worry',
                developerMessage: 'Hey Man! This is bad'
            },
            statusCode: 500
        });
    })

Example of error log

alt text

Example of log

alt text

Example of response

alt text

Examples on Slack

alt text alt text

TODO

  • Check Lazy Requests
  • Save requests on database (mongo?)
0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago