fastify-cloudevents
Advanced tools
Comparing version 0.1.2 to 0.1.3
# Change Log | ||
## [0.1.3](https://github.com/smartiniOnGitHub/fastify-cloudevents/releases/tag/0.1.3) (2018-11-14) | ||
Summary Changelog: | ||
- Add the plugin configuration option `includeHeaders` so that when `true` all request headers will be put in generated CloudEvents (but by default is `false`) | ||
- Update both examples with both values for the plugin configuration option `includeHeaders` to se default behavior (written the same) and not | ||
## [0.1.2](https://github.com/smartiniOnGitHub/fastify-cloudevents/releases/tag/0.1.2) (2018-11-13) | ||
@@ -4,0 +9,0 @@ Summary Changelog: |
@@ -28,2 +28,3 @@ /* | ||
baseNamespace: 'com.github.smartiniOnGitHub.fastify-cloudevents.example', | ||
includeHeaders: true, | ||
cloudEventOptions: { | ||
@@ -58,2 +59,3 @@ strict: true // enable strict mode in generated CloudEvents, optional | ||
idGenerator: gen, | ||
includeHeaders: k.includeHeaders, | ||
onRequestCallback: loggingCallback, | ||
@@ -102,3 +104,3 @@ preHandlerCallback: loggingCallback, | ||
const stream = fs.createReadStream(path.join(scriptRelativeFolder, 'home.html')) | ||
reply.type('text/html').send(stream) | ||
reply.type('text/html; charset=utf-8').send(stream) | ||
}) | ||
@@ -110,3 +112,3 @@ // example route, to return current timestamp but in async way | ||
fastify.listen(k.port, k.address, (err) => { | ||
fastify.listen(k.port, k.address, (err, address) => { | ||
if (err) { | ||
@@ -129,3 +131,3 @@ const ce = new fastify.CloudEvent(gen.next().value, | ||
} | ||
console.log(`Server listening on ${fastify.server.address().port}`) | ||
console.log(`Server listening on ${address}`) | ||
const ce = new fastify.CloudEvent(gen.next().value, | ||
@@ -132,0 +134,0 @@ `${k.baseNamespace}.listen`, |
@@ -25,2 +25,3 @@ /* | ||
baseNamespace: 'com.github.smartiniOnGitHub.fastify-cloudevents.example', | ||
includeHeaders: false, // same as default value | ||
cloudEventOptions: { | ||
@@ -50,2 +51,3 @@ strict: true // enable strict mode in generated CloudEvents, optional | ||
idGenerator: gen, | ||
includeHeaders: k.includeHeaders, | ||
onRequestCallback: loggingCallback, | ||
@@ -71,3 +73,3 @@ preHandlerCallback: loggingCallback, | ||
const stream = fs.createReadStream(path.join(scriptRelativeFolder, 'home.html')) | ||
reply.type('text/html').send(stream) | ||
reply.type('text/html; charset=utf-8').send(stream) | ||
}) | ||
@@ -79,7 +81,7 @@ // example route, to return current timestamp but in async way | ||
fastify.listen(k.port, k.address, (err) => { | ||
fastify.listen(k.port, k.address, (err, address) => { | ||
if (err) { | ||
throw err | ||
} | ||
console.log(`Server listening on ${fastify.server.address().port}`) | ||
console.log(`Server listening on ${address}`) | ||
const ce = new fastify.CloudEvent(gen.next().value, | ||
@@ -86,0 +88,0 @@ `${k.baseNamespace}.listen`, |
{ | ||
"name": "fastify-cloudevents", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Fastify Plugin to serialize events in the CloudEvents standard format", | ||
@@ -5,0 +5,0 @@ "main": "src/plugin", |
@@ -64,2 +64,3 @@ # fastify-cloudevents | ||
- `idGenerator`, a generator function that returns the id (if possible, unique) for any CloudEvent | ||
- `includeHeaders`, a boolean flag that when `true` tells that request headers will be put in generated CloudEvents (but by default is `false`) | ||
- `onRequestCallback`, callback who will handle the generated CloudEvents, in Fastify hook `onRequest` | ||
@@ -66,0 +67,0 @@ - `preHandlerCallback`, callback who will handle the generated CloudEvents, in Fastify hook `preHandler` |
@@ -26,2 +26,3 @@ /* | ||
idGenerator = idMaker(), | ||
includeHeaders = false, | ||
onRequestCallback = null, | ||
@@ -40,2 +41,3 @@ preHandlerCallback = null, | ||
ensureIsObject(idGenerator, 'idGenerator') | ||
ensureIsBoolean(includeHeaders, 'includeHeaders') | ||
ensureIsFunction(onRequestCallback, 'onRequestCallback') | ||
@@ -112,2 +114,3 @@ ensureIsFunction(preHandlerCallback, 'preHandlerCallback') | ||
fastify.addHook('onRequest', (req, res, next) => { | ||
const headers = (includeHeaders === null || includeHeaders === true) ? req.headers : null | ||
const ce = new fastify.CloudEvent(idGenerator.next().value, | ||
@@ -121,3 +124,3 @@ `${baseNamespace}.onRequest`, | ||
id: req.id, | ||
headers: req.headers, | ||
headers: headers, | ||
method: req.method, | ||
@@ -142,2 +145,3 @@ originalUrl: req.originalUrl, | ||
fastify.addHook('preHandler', (request, reply, next) => { | ||
const headers = (includeHeaders === null || includeHeaders === true) ? request.headers : null | ||
const ce = new fastify.CloudEvent(idGenerator.next().value, | ||
@@ -150,3 +154,3 @@ `${baseNamespace}.preHandler`, | ||
id: request.id, | ||
headers: request.headers, | ||
headers: headers, | ||
params: request.params, | ||
@@ -174,2 +178,3 @@ query: request.query, | ||
fastify.addHook('onSend', (request, reply, payload, next) => { | ||
const headers = (includeHeaders === null || includeHeaders === true) ? request.headers : null | ||
const ce = new fastify.CloudEvent(idGenerator.next().value, | ||
@@ -182,3 +187,3 @@ `${baseNamespace}.onSend`, | ||
id: request.id, | ||
headers: request.headers, | ||
headers: headers, | ||
params: request.params, | ||
@@ -277,2 +282,8 @@ query: request.query, | ||
function ensureIsBoolean (arg, name) { | ||
if (arg !== null && typeof arg !== 'boolean') { | ||
throw new TypeError(`The argument '${name}' must be a boolean, instead got a '${typeof arg}'`) | ||
} | ||
} | ||
function ensureIsObject (arg, name) { | ||
@@ -279,0 +290,0 @@ if (arg !== null && typeof arg !== 'object') { |
39255
569
94