Skip to content

Commit

Permalink
wip: loggable event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
eadmundo committed May 11, 2022
1 parent d3de406 commit f32852a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
createKVCredentialsVerifier
} from './lib/basicAuthenticationHandler'
import { createVerifyJwksHandler } from './lib/verifyJwksHandler'
import { createLoggableEventHandler } from './lib/loggableEventHandler'

export {
createSitesHandler,
Expand All @@ -19,4 +20,5 @@ export {
createCookieEncryptor,
generateStateParam,
createVerifyJwksHandler,
createLoggableEventHandler
}
2 changes: 1 addition & 1 deletion lib/logTransportHandler/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test('send log event', async t => {
const transport = sinon.spy()

const mf = new Miniflare({
scriptPath: './test/worker/dist/index.js',
scriptPath: './util/worker/dist/index.js',
buildCommand: 'npm run build-test',
globals: {
createHandlerImportName: 'createLogTransportHandler',
Expand Down
16 changes: 16 additions & 0 deletions lib/loggableEventHandler/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Logger } from '@autotelic/worker-logger'

export const createLoggableEventHandler = ({
router,
logOptions = {}
}) => {
const log = new Logger(logOptions)

return async event => {
const request = new Request(event.request)
request.log = log
const res = await router.handle(request, event)
event.waitUntil(request.log.report())
return res
}
}
7 changes: 7 additions & 0 deletions lib/loggableEventHandler/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import test from 'ava'
import { createLoggableEventHandler } from './index.js'

test('createLoggableEventHandler', async t => {
const eventHandler = createLoggableEventHandler({})
t.pass()
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
"fix": "npm run lint -- --fix",
"lint": "standard",
"test": "ava --verbose",
"build-test": "esbuild --bundle --sourcemap --outdir=./test/worker/dist ./test/worker/index.js",
"build-test": "esbuild --bundle --sourcemap --outdir=./util/worker/dist ./util/worker/index.js",
"validate": "npm run lint && npm run test",
"verify": "miniflare examples/verify-jwks/index.js"
},
"author": "",
"license": "MIT",
"dependencies": {
"@autotelic/worker-logger": "github:autotelic/worker-logger#main",
"@cloudflare/kv-asset-handler": "^0.2.0",
"@worker-tools/request-cookie-store": "^0.4.2",
"base64url": "^3.0.1",
Expand Down
File renamed without changes.

0 comments on commit f32852a

Please sign in to comment.