Skip to content
This repository was archived by the owner on Feb 18, 2021. It is now read-only.

Commit e4ffdad

Browse files
committed
Merge pull request #3 from Raynos/http-support
add http support
2 parents a42c186 + beb2b4a commit e4ffdad

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ status_code.200:1|c
3838
response_time:100|ms
3939
```
4040

41+
### Per route example
42+
4143
However, it's **highly recommended** that you set `req.statsdKey` which
4244
will be used to namespace the stats. Be aware that stats will only be logged
4345
once a response has been sent; this means that `req.statsdKey` can be
@@ -73,6 +75,24 @@ http.get.home.status_code.200:1|c
7375
http.get.home.response_time:100|ms
7476
```
7577

78+
### Plain http example
79+
80+
This module also works with any `http` server
81+
82+
```js
83+
var http = require('http');
84+
var expressStatsd = require('express-statsd');
85+
86+
var monitorRequest = expressStatsd();
87+
88+
http.createServer(function (req, res) {
89+
monitorRequest(req, res);
90+
91+
// do whatever you want, framework, library, router
92+
res.end('hello world');
93+
}).listen(3000);
94+
```
95+
7696
## Options
7797

7898
``` js

lib/express-statsd.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ module.exports = function expressStatsdInit (options) {
4444
res.once('error', cleanup);
4545
res.once('close', cleanup);
4646

47-
next();
47+
if (next) {
48+
next();
49+
}
4850
};
4951
};

0 commit comments

Comments
 (0)