https://github.com/juninmd/shazam-middleware
https://github.com/juninmd/shazam-middleware
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/juninmd/shazam-middleware
- Owner: juninmd
- Created: 2017-07-11T21:02:50.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2026-01-24T10:38:49.000Z (5 months ago)
- Last Synced: 2026-01-24T11:07:39.450Z (5 months ago)
- Language: JavaScript
- Size: 99.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# shazam-middleware
[](https://www.codacy.com/app/jr_acn/shazam-middleware?utm_source=github.com&utm_medium=referral&utm_content=juninmd/shazam-middleware&utm_campaign=Badge_Grade)
[](https://npmjs.org/package/shazam-middleware)
[](https://npmjs.org/package/shazam-middleware)
[](https://github.com/juninmd/shazam-middleware/issues)
[](https://github.com/juninmd/shazam-middleware/network)
[](https://twitter.com/intent/tweet?text=Wow:&url=%5Bobject%20Object%5D)
## 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
* [Node](https://nodejs.org/en/)
* [Express](https://www.npmjs.com/package/express)
## Installation
```bash
npm install --save shazam-middleware
```
or
```bash
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
```js
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)
```js
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.
```js
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

## Example of log

## Example of response

## Examples on Slack


## TODO
* Check Lazy Requests
* Save requests on database (mongo?)