@hoajs/context-storage
v0.1.2
Published
Context storage middleware for Hoa.
Downloads
201
Readme
@hoajs/context-storage
Context storage middleware for Hoa.
Installation
$ npm i @hoajs/context-storage --saveQuick Start
import { Hoa } from 'hoa'
import { contextStorage, getContext } from '@hoajs/context-storage'
const app = new Hoa()
app.use(contextStorage())
app.use(async (ctx, next) => {
ctx.state.requestId = crypto.randomUUID()
await next()
})
app.use(async (ctx, next) => {
log('Request start')
await doSomething()
log('Request end')
})
function log (msg) {
const ctx = getContext()
console.log(`[${ctx.state.requestId}] ${msg}`)
}
export default appDocumentation
The documentation is available on hoa-js.com
Test (100% coverage)
$ npm testLicense
MIT
