daruk-request-id
Advanced tools
Comparing version 0.4.0 to 0.4.1
{ | ||
"name": "daruk-request-id", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "koa request id", | ||
"main": "./lib/index.js", | ||
"typings": "./index.d.ts", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "node ./node_modules/.bin/tsc" | ||
"build": "tsc" | ||
}, | ||
@@ -10,0 +11,0 @@ "repository": { |
@@ -0,0 +0,0 @@ # daruk-request-id |
@@ -6,7 +6,7 @@ /** | ||
/*! | ||
* x-request-id | ||
* Copyright(c) 2015 Fangdun Cai | ||
* MIT Licensed | ||
*/ | ||
/*! | ||
* x-request-id | ||
* Copyright(c) 2015 Fangdun Cai | ||
* MIT Licensed | ||
*/ | ||
@@ -17,3 +17,3 @@ /** | ||
import uuid from "uuid/v4"; | ||
import uuid from 'uuid/v4'; | ||
@@ -30,4 +30,4 @@ const HTTP_X_REQUEST_ID_HEADER = 'X-Request-Id'; | ||
* @param {string} [key=HTTP_X_REQUEST_ID_HEADER] | ||
* @param {bool} [noHyphen=false] | ||
* @param {bool} [inject=false] | ||
* @param {boolean} [noHyphen=false] | ||
* @param {boolean} [inject=false] | ||
* @api public | ||
@@ -43,8 +43,8 @@ */ | ||
export function xRequestId (options: Options, app: any) { | ||
options = options || {} | ||
const key = options.key || HTTP_X_REQUEST_ID_HEADER | ||
const noHyphen = !!options.noHyphen | ||
const inject = !!options.inject | ||
options = options || {}; | ||
const key = options.key || HTTP_X_REQUEST_ID_HEADER; | ||
const noHyphen = !!options.noHyphen; | ||
const inject = !!options.inject; | ||
if (inject) { | ||
if (!app) throw new TypeError('`app` must be required!') | ||
if (!app) throw new TypeError('`app` must be required!'); | ||
Object.defineProperty(app.request, 'id', { | ||
@@ -57,3 +57,3 @@ get: function () { | ||
} | ||
}) | ||
}); | ||
Object.defineProperty(app.context, 'id', { | ||
@@ -67,8 +67,8 @@ get: function () { | ||
return (ctx: any, next: Function) => { | ||
var id = ctx.id || ctx.query[key] || ctx.get(key) || uuid() | ||
if (noHyphen) id = id.replace(/-/g, '') | ||
if (inject) ctx.request.id = id | ||
ctx.set(key, id) | ||
var id = ctx.id || ctx.query[key] || ctx.get(key) || uuid(); | ||
if (noHyphen) id = id.replace(/-/g, ''); | ||
if (inject) ctx.request.id = id; | ||
ctx.set(key, id); | ||
return next() | ||
} | ||
} |
@@ -0,0 +0,0 @@ { |
Sorry, the diff of this file is not supported yet
20571
11
129