fastify-cloudevents
Advanced tools
Comparing version 0.2.1 to 0.2.2
# Change Log | ||
## [0.2.2](https://github.com/smartiniOnGitHub/fastify-cloudevents/releases/tag/0.2.2) (2018-12-25) | ||
Summary Changelog: | ||
- Updated dependencies to latest release | ||
- Add client IP address in a custom attribute inside the data section of generated CloudEvent instances | ||
## [0.2.1](https://github.com/smartiniOnGitHub/fastify-cloudevents/releases/tag/0.2.1) (2018-12-20) | ||
@@ -4,0 +9,0 @@ Summary Changelog: |
{ | ||
"name": "fastify-cloudevents", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Fastify Plugin to serialize events in the CloudEvents standard format", | ||
@@ -15,7 +15,7 @@ "main": "src/plugin", | ||
"fastify-plugin": "^1.4.0", | ||
"fast-json-stringify": "^1.9.2", | ||
"fast-json-stringify": "^1.10.0", | ||
"cloudevent": "^0.2.1" | ||
}, | ||
"devDependencies": { | ||
"fastify": "^1.13.2", | ||
"fastify": "^1.13.3", | ||
"simple-get": "^3.0.3", | ||
@@ -22,0 +22,0 @@ "standard": "^12.0.1", |
@@ -101,2 +101,17 @@ /* | ||
/** | ||
* Extract and build the value for the client IP address, | ||
* useful to add into the CloudEvent in a custom attribute inside data. | ||
* | ||
* @param {!object} req the request | ||
* @return {string} the IP address, as a string | ||
*/ | ||
function buildClientIP (req) { | ||
if (req === undefined || req === null) { | ||
throw new Error('Illegal value for request: undefined or null') | ||
} | ||
const ip = req.connection.remoteAddress | ||
return ip | ||
} | ||
// execute plugin code | ||
@@ -123,2 +138,3 @@ fastify.decorate('CloudEvent', cloudEventHandler) | ||
const sourceUrl = buildSourceUrl(req.url) | ||
const clientIp = buildClientIP(req) | ||
const ce = new fastify.CloudEvent(idGenerator.next().value, | ||
@@ -137,3 +153,4 @@ `${baseNamespace}.onRequest`, | ||
upgrade: req.upgrade, | ||
url: req.url | ||
url: req.url, | ||
clientIp: clientIp | ||
}, | ||
@@ -156,2 +173,3 @@ res: { } | ||
const sourceUrl = buildSourceUrl(request.req.url) | ||
const clientIp = buildClientIP(request.req) | ||
const ce = new fastify.CloudEvent(idGenerator.next().value, | ||
@@ -170,3 +188,4 @@ `${baseNamespace}.preHandler`, | ||
method: request.req.method, | ||
url: request.req.url | ||
url: request.req.url, | ||
clientIp: clientIp | ||
}, | ||
@@ -191,2 +210,3 @@ reply: { | ||
const sourceUrl = buildSourceUrl(request.req.url) | ||
const clientIp = buildClientIP(request.req) | ||
const ce = new fastify.CloudEvent(idGenerator.next().value, | ||
@@ -205,3 +225,4 @@ `${baseNamespace}.onSend`, | ||
method: request.req.method, | ||
url: request.req.url | ||
url: request.req.url, | ||
clientIp: clientIp | ||
}, | ||
@@ -208,0 +229,0 @@ reply: { |
43481
617
Updatedfast-json-stringify@^1.10.0