9d9a456b28
* actual npm update * migrating plugin * fix hydration (todo redis) * fix dashboard title * linting fixes * fix ssr dev logs * fix shared build * more linting fixes * more lint fixes * preview dockerfile fix * fix max stack trace issue
26 lines
727 B
TypeScript
26 lines
727 B
TypeScript
import { getContext } from 'unctx'
|
|
import { consola, type ConsolaInstance } from 'consola'
|
|
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
|
|
interface DevLogsServerContext {
|
|
consola: ConsolaInstance
|
|
}
|
|
|
|
const asyncContext = getContext<DevLogsServerContext>('nuxt-dev-logs', {
|
|
asyncContext: true,
|
|
AsyncLocalStorage
|
|
})
|
|
|
|
/**
|
|
* Importing `consola` from a nuxt plugin scope will give us a different instance. We have to pass through the nitro version
|
|
* through an async context.
|
|
*/
|
|
export default defineNitroPlugin((nitroApp) => {
|
|
if (!import.meta.dev) return
|
|
|
|
const handler = nitroApp.h3App.handler
|
|
nitroApp.h3App.handler = (event) => {
|
|
return asyncContext.callAsync({ consola }, () => handler(event))
|
|
}
|
|
})
|