Skip to content
This repository was archived by the owner on Dec 10, 2018. It is now read-only.

Typescript types #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ All options are optional.

* `dogstatsd` node-dogstatsd client. `default = new (require("node-dogstatsd")).StatsD()`
* `stat` *string* name for the stat. `default = "node.express.router"`
* `tags` *array* of tags to be added to the histogram. `default = []`
* `tags` either:
* *array* of tags to be added to the histogram
* *function* that takes `req` and `res`, returning an array of tags
* `default = []`
* `path` *boolean* include path tag. `default = false`
* `method` *boolean* include http method tag. `default = false`
* `protocol` *boolean* include protocol tag. `default = false`
Expand Down
9 changes: 9 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { RequestHandler } from 'express'

// name 'connectDatadog' doesn't really matter
// Just make sure that the function and namespace below have the same names
declare function connectDatadog(options: any): RequestHandler
declare namespace connectDatadog {

}
export = connectDatadog
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function (options) {
var baseUrl = (base_url !== false) ? req.baseUrl : '';
var statTags = [
"route:" + baseUrl + req.route.path
].concat(tags);
].concat(typeof tags === 'function' ? tags(req, res) : tags);

if (options.method) {
statTags.push("method:" + req.method.toLowerCase());
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "connect-datadog",
"version": "0.0.6",
"version": "0.0.7",
"description": "Datadog middleware for Connect JS / Express",
"main": "index.js",
"repository": {
Expand All @@ -15,6 +15,10 @@
"license": "MIT",
"readmeFilename": "README.md",
"dependencies": {
"express": "^4.16.3",
"node-dogstatsd": "0.0.6"
},
"devDependencies": {
"@types/express": "^4.16.0"
}
}