shazam-middleware
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
- Activate webhook on slack, to get your UrlHook :D
- https://{yourslackname}.slack.com/apps/A0F7XDUAZ-incoming-webhooks
- Doc: https://api.slack.com/incoming-webhooks
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 = ; // Don't forget to configure the paramtersconst shazam = slack: urlHook: processenvurlHook channel: processenvchannel iconUrl: processenviconUrl botusername: processenvbotusername api: name: 'My App' version: 1 ; // Activate validation on process `uncaughtException` and `unhandledRejection`shazamhandler; // Now, we wanna log all requestsapp; // Look Here, one route with errorapp // Now, we will look for all exceptions from ours routesapp; // Start the Serverapp // Fine! It`s All!
If you return a object like this patern, and use next(), you can trigger the message on Slack Channel.
app
Example of error log
Example of log
Example of response
Examples on Slack
TODO
- Check Lazy Requests
- Save requests on database (mongo?)