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 c1ae118
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 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
}
14 changes: 14 additions & 0 deletions lib/loggableEventHandler/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Logger } from '@autotelic/worker-logger'

export const createLoggableEventHandler = ({
router,
logOptions = {}
}) => {
return async event => {
const request = new Request(event.request)
request.log = new Logger(logOptions)
const res = await router.handle(request, event)
event.waitUntil(request.log.report())
return res
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@autotelic/worker-logger": "github:autotelic/worker-logger",
"@cloudflare/kv-asset-handler": "^0.2.0",
"@worker-tools/request-cookie-store": "^0.4.2",
"base64url": "^3.0.1",
Expand Down

0 comments on commit c1ae118

Please sign in to comment.